1

I'm trying, without success, to disable pagination only in a specific category (where I'm showing all the posts of that category listed by years). Someone can help me? Thanks.

2
  • i need a snippet for all my categories, this only work for one Commented Jun 30, 2022 at 10:34
  • @rafikbennacer I converted your solution into a comment, I'm assuming it was intended as a comment, but I couldn't figure out which solution you were commenting on. Don't post comments as solutions to other peoples answers in future though. If you have a different question you should ask it as a new question rather than finding a similar question that's close
    – Tom J Nowell
    Commented Jun 30, 2022 at 11:19

2 Answers 2

2

You can try this, replacing my_cat with your category slug. This will modify the main query just before rendering the loop on the archive page of your category.

add_action( 'pre_get_posts', 'wpse_disable_pagination' );
function wpse_disable_pagination( $query ) {

  if( is_category( 'my_cat' ) {
    query->set( 'posts_per_page', '-1' );
  }

}
1

@bynicolas thanks! One shot, one kill :)

This is the modified sintax of your snippet that worked for me:

add_action( 'pre_get_posts', 'wpse_disable_pagination' );
function wpse_disable_pagination( $query )
{
  if ( is_category( 'newsletter' ) )
  $query->set( 'posts_per_page', '-1' );
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.