How do I remove pagination from just some Categories?


I have site I’m building that has a bunch of categories, but one category and its subcategories are special. They have an advanced custom field for a Google Map location. I have the map with everything on a category page working, but when looping through the posts I obviously only get the posts on the page. So, for those archive pages for those categories, and only those categories, I need to remove pagination. I know how to adjust pagination in functions.php and in WordPress setting, but I don’t know how to get all posts, but I’ve searched and played with ideas but nothing got close to doing what I need. Here’s what I’ve currently got:

function exclude_category( $query ) {
    $this_cat = get_query_var('category_name');
    if ( $query->is_home() && $query->is_main_query() ) {
        $query->set( 'cat', '-8,-54' );
        $query->set( 'posts_per_page', 7 ); // Homepage 7 posts.
    if (
        $this_cat == 'Places' ||
        $this_cat == 'Africa & Australasia' ||
        $this_cat == 'Asia' ||
        $this_cat == 'Central Europe' ||
        $this_cat == 'Eastern Europe' ||
        $this_cat == 'Israel/Palestine & the Middle East' ||
        $this_cat == 'North America' ||
        $this_cat == 'Scandinavia' ||
        $this_cat == 'South America' ||
        $this_cat == 'Western Europe'
        $query->set('posts_per_page',10000); // Get all the places at once for map.
add_action( 'pre_get_posts', 'exclude_category' );

I’ve thought about throwing out the WP_Query and running it again to get all, and if I don’t get a better solution, that might be where I end up.

J. A. Streich 10 months 2022-08-26T12:45:29-05:00 0 Answers 0 views 0

Leave an answer