1

I am trying to use pre_get_posts to display a custom number of posts on my taxonomy category pages. I can get this to work for a single post type (taxonomy) but if I try to use more than one, say in an array, I cannot get it to work. I am not great with php and a little direction here would be awesome. Here is what I am working with now:

// Change the number of posts that show up on the taxonomy template 
function custom_tax_post_count ( $query ) {
    if (($query->is_tax('taxonomy_1') ))      
    $query->set( 'posts_per_page', '-1' );
}
add_action( 'pre_get_posts', 'custom_tax_post_count' );

I would like something like this:

// Change the number of posts that show up on the taxonomy template 
function custom_tax_post_count ( $query ) {
    if (($query->is_tax(array('taxonomy_1', 'taxonomy_2')) ))      
    $query->set( 'posts_per_page', '-1' );
}
add_action( 'pre_get_posts', 'custom_tax_post_count' );
1

I answered my own question I just implemented it wrong when testing it on my end (mis-typed the taxonomy).

This is correct:

// Change the number of posts that show up on the taxonomy template 
function custom_tax_post_count ( $query ) { 
  if (($query->is_tax(array('taxonomy_1', 'taxonomy_2')) ))
    $query->set( 'posts_per_page', '-1' ); 
} 
add_action( 'pre_get_posts', 'custom_tax_post_count' );

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.