WordPress.org

Support

Support » Themes and Templates » pre_get_posts and pagination

pre_get_posts and pagination

  • I can not for the life of me get a modified main query and pagination working together.

    Desired outcome:

    On home template, custom query (with new wp_query) and main query both running. Custom query grabs one post and main query grabs the rest (with offset)

    What I have:

    if ( $query->is_home() && $query->is_main_query() ) { // Run only on the homepage
    	$query->set('offset', 1);
    }

    The offset works correctly only on the main loop on the home page but pagination is broken.

    If I remove the ‘is_main_query’ function, pagination works correctly but the offset runs on all queries including the wp_query custom one.

    Grabbing the $paged query vars and adding them to the query does not help.

    Thoughts?

  • The topic ‘pre_get_posts and pagination’ is closed to new replies.
Skip to toolbar