Using pre_get_posts
-
Hi,
On this closed topic Chip Bennett advises strongly to use pre_get_posts, but I can’t find out how to combine the function he describes with my Loop.
What do I need to change in my Loop? It looks like this now, and Chip will be mad at me, but I want to ignore sticky posts, and all other solutions I found online break pagination:
<?php global $query_string; query_posts( $query_string . '&ignore_sticky_posts=1'); ?> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <?php get_template_part( 'content', get_post_format() ); ?> <?php endwhile; else: ?> <?php endif; ?>
I already put the function Chip describes in my functions.php:
function breatheout_filter_pre_get_posts( $query ) { if ( $query->is_main_query ) { $query->set( 'ignore_sticky_posts', '1' ); } } add_action( 'pre_get_posts', 'breatheout_filter_pre_get_posts' );
Thanks for your time!
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Using pre_get_posts’ is closed to new replies.