Display Posts on Custom Page

If News is a category of posts, then: First, find out the category ID, login to wp-admin, go Posts->Categories, mouse over the ‘News’ category, and cat id should be shown under the left corner of the browser (for chrome this works, not sure about other browsers). Add the following code into your function.php function my_news_category( … Read more

Posts loop displaying the same post data

Try using WP_Query instead. So the code would be like: <?php $args = array( ‘posts_per_page’ => 5, ‘cat’ => 2, ‘offset’ => 0, ‘order’ => ‘date’, ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’ ); $post_query = new WP_Query($args); if($post_query->have_posts()) : while($post_query->have_posts()) : $post_query->the_post(); ?> <div><?php the_permalink(); ?></div> <div><?php the_title(); ?></div> <div><?php the_content(); ?></div> <?php endwhile; endif; … Read more

Avoiding “Missed Schedule” errors when inserting future posts

The missed schedule warning comes form those lines: https://github.com/WordPress/WordPress/blob/f884d7973b052c3efe0901bb136b9898ece8aa39/wp-admin/includes/class-wp-posts-list-table.php#L998,L999 It should be independent on any cron event, as the warning is being displayed only in case the current UTC time – post_date_gmt > 0 – there is no other condition (except for post having the future status). In order to debug the issue, check what … Read more

How many posts does the loop return?

Try reversing the logic, put the dividing line before the post but only do it after the first post. To answer your question though, you can get the loop count with the following: global $wp_query; $count = count( $wp_query->posts ); // or $count = $wp_query->post_count;

Excluding posts not working

Have a look at https://codex.wordpress.org/Class_Reference/WP_Query, and maybe try passing your args in an array. Above page lists this exact example, which should work: // This WILL work $exclude_ids = array( 1, 2, 3 ); $query = new WP_Query( array( ‘post__not_in’ => $exclude_ids ) );

Insert sometext after first h3 in content

Note returning $content[0]; when !is_single() you’ll get non-exist errors. You can accomplish what you’re after with somthing like: add_filter(‘the_content’, function ($content){ if (!is_single()) return $content; $div = “🎅🏻”; return preg_replace(‘/<\/h3>/i’, “</h3>”.$div, $content, 1); }); note the third parameter of preg_replace() is the limit, setting to 1 will restrict the replace to the first match.

Is it possible to add/tick a category to a post when it is created?

You can add a category on post creation with this code : $postType = “post”; add_action(“save_post_” . $postType, function ($post_ID, \WP_Post $post, $update) { if (!$update) { // default values for new posts $post_categories = [get_option(“default_category”)]; wp_set_post_terms( $post->ID , $post_categories , “category” ); return; } // here, operations for updated posts }, 10, 3);

Worpdress function for difference dates

Put this in the appropriate template. <?php echo human_time_diff( get_the_time(‘U’), current_time(‘timestamp’) ) . ‘ ago’; ?> Normally the php file you should look for would be entry-meta.php Remember to use a child theme..