Search code examples
wordpresscustom-post-typetaxonomy

Display a number of post per page in custom taxonomy page in Wordpress


I have the following function in my functions.php, that changes the number of posts displayed per page in the custom post type archive page. How can I also target the corresponding taxonomy page(taxonomy-case.php)? Is there something similar to "is_post_type_taxonomy"?

// Post number limits
function my_cptui_change_posts_per_page( $query ) {
    if ( is_admin() || ! $query->is_main_query() ) {
       return;
    }

    if ( is_post_type_archive( 'case' ) ) {
       $query->set( 'posts_per_page', 8 );
    }
}
add_filter( 'pre_get_posts', 'my_cptui_change_posts_per_page' );

Solution

  • Add below code inside your function and check if it's working. Don't forget to replace your category with your taxonomy name.

    if (is_tax( 'your-category' ) ) { 
       $query->set( 'posts_per_page', 8 );
    }