Site logo

Archived topic

Show more posts in one category

3 replies · Started by Sami on September 8, 2019

Viewing posts 1–4 of 4

I want to show 30 posts for category 9 and 10 posts for all other categories. By searching the forum I've found this code which I edited a little but it somehow doesn't work, do you have an idea why?

add_action( 'pre_get_posts', 'tu_change_posts_per_page', 1 );
function tu_change_posts_per_page( $query ) {
    if ( ( ! is_main_query() && ! is_category('9') ) || is_admin() ) {
        return;
    }

    if ( ! $query->is_paged && ! is_category('9') ) {
        $query->set( 'posts_per_page', 30 );
    }
}

Hi there,

Try this:

add_action( 'pre_get_posts', function( $query ) {
    if ( ! is_main_query() || is_admin() ) {
        return;
    }

    if ( ! is_paged() && is_category( 9 ) ) {
        $query->set( 'posts_per_page', 30 );
    }
} );

Let me know :)

Thank you, that works!

You're welcome :)

This archived topic is closed to new replies.