0

I have a site that lists vehices for sale. One page is a stocklist which shows 6 entries per page as standard. The news page also has this function.

Is there a simple way of overriding all pagination code to display all posts?

1

You can use pre_get_posts to override the posts_per_page setting

add_action( 'pre_get_posts', function ( $q )
{
    if (    $q->is_main_query() // Only target the main query
         && !$q->is_singular() // Do not target singular posts
    ) {
        $q->set( 'posts_per_page', -1 );
    }
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.