Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save vovadocent/9b2dfb17839085c24fdc7864baede1d6 to your computer and use it in GitHub Desktop.
Save vovadocent/9b2dfb17839085c24fdc7864baede1d6 to your computer and use it in GitHub Desktop.
Fixing Custom Post Type Archive Pagination WordPress 404
<?php
function custom_posts_per_page($query) {
if ( !is_admin() && $query->is_archive() && is_post_type_archive('packages') ) {
$def_ppp = 4;
$ppp = isset($_COOKIE['ppp']) && (int) $_COOKIE['ppp'] > $def_ppp ? intval($_COOKIE['ppp']) : $def_ppp;
set_query_var('posts_per_page', $ppp);
set_query_var('city', 0);
set_query_var('class', 0);
}
}
add_action('pre_get_posts', 'custom_posts_per_page');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment