0

How can I display a number of 20 posts in my Page Archive (Taxonomy Archive)?

For example: in wordpress settings in Reading I use: Blog pages show at most 10 posts.
This works in arhive page, but when I click on the categories (taxonomy's) it display only 10 posts.

I have this function that displays the archive:

function iti_custom_posts_per_page($query)
    {
        switch ( $query->query_vars['post_type'] )
        {
            case 'trailers':  // Post Type named 'iti_cpt_1'
                $query->query_vars['posts_per_page'] = 20;
                break;

            case 'persoane':  // Post Type named 'iti_cpt_2'
                $query->query_vars['posts_per_page'] = 6;
                break;


            case 'serial':  // Post Type named 'iti_cpt_3'
                $query->query_vars['posts_per_page'] = 6;
                break;

            default:
                break;
        }
        return $query;
    }

    if( !is_admin() )
    {
        add_filter( 'pre_get_posts', 'iti_custom_posts_per_page' );
    }
1

If I understand your question right you seem to have the code that seems close to what you want, but doesn't function correctly. What I have trouble following is that your description talks about taxonomy archives, but your code seems to be about custom post type archives.

I would suggest to use more appropriate query methods rather than working with vars directly:

  • $query->is_tax() to check for taxonomy archives
  • $query->is_post_type_archive() to check for CPT archives
  • $query->set() to modify query vars

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.