Using pre_get_posts to set posts per page, how do I?

You’re almost there mate. Try this though.

<?php
    add_action('pre_get_posts', 'filter_press_tax');

    function filter_press_tax( $query ){
        if( $query->is_tax('press') && $query->has_term('press')):
            $query->set('posts_per_page', 5);
            return;
        endif;
    }
?>

You can use any conditional tag or any argument that can be passed to WP_Query to test your condition or set a new value via pre_get_posts. Also try $query->get('taxonomy') / $query->get('term').
And check this for $query‘s set and get methods.

Leave a Comment