how to use pre_gets_posts to exclude one queried ID from homepage loop

Couple of issues here You custom query should be inside your conditional statement Use get_posts which only returns the $posts property wp_reset_query() is used with query_posts which you must never ever use No need to the $post global Your code should look something like this add_action( ‘pre_get_posts’, ‘cdbz_modify_main_query’ ); function cdbz_modify_main_query( $query ) { if … Read more

Check for the main query from the template

Use in_the_loop(), it returns true if we are in the main loop, false if we are not, like on a custom query loop Return: (bool) True if caller is within loop, false if loop hasn’t started or ended. The difference between is_main_query() and in_the_loop() is that is_main_query() uses WP_Query::is_main_query() which in turn uses the global … Read more

Add “showing posts x to x of y” in custom post type paginated loop

All query objects have a few built in vars that can help you display this. Assuming your custom query object is $query: The total number of posts across all pages is $query->found_posts The total number of posts for the current page is $query->post_count The current page number is $query->query_vars[‘paged’] The number of posts per page … Read more