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.
-
i need a snippet for all my categories, this only work for one– rafik bennacerCommented 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
Add a comment
|
2 Answers
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' );
}
}
@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' ); }