Skip to content

Instantly share code, notes, and snippets.

@rtpHarry
Last active June 5, 2025 11:57
Show Gist options
  • Save rtpHarry/8035d17413ff036c96d628c527ba0be2 to your computer and use it in GitHub Desktop.
Save rtpHarry/8035d17413ff036c96d628c527ba0be2 to your computer and use it in GitHub Desktop.
Force All Results For Specific Archive Pages
<?php
add_action('pre_get_posts', function ($query) {
if (
!is_admin() &&
// for me I commented this out in the end as my ajax grid sort by query was going back to a smaller set of results
// but it is risky, as it could affect other parts of the site like related posts, or sidebar widgets
// test it out on your site, and if it breaks then you will need to dig in and find a way to detect which query
// to filter:
// $query->is_main_query() &&
(
(is_post_type_archive('lodge')) ||
(is_tax('collection'))
)
) {
$query->set('posts_per_page', -1);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment