Many people report problems with pagination of custom queries or custom post type archives: url/page/2 produces a 404 even though all the setup is correct.

Many end up figuring out that this is occurring because the posts_per_page of their custom loop is less than the maximum posts per page setting in the admin, which they fix by changing

 Settings » Reading » "Blog pages show at most: ____ posts" 

to 1.

This works in my situation, but I would much prefer to change this only for this specific custom query, rather than the whole site. Is this possible?

The relevant WP_Query is this:

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$wp_query = new WP_Query( array(
'post_type' => 'publication',
'posts_per_page' => 5,

2 Answers 2


I assume you have a custom post type: publication

in functions.php place that code:

function mk_parse_query($query) {
  if ($query->query_vars['post_type'] == 'publication')) {
        set_query_var( 'posts_per_page', 5 );
if( !is_admin() ) {

Similar code works for me, but in my case I was struggling with 404 on custom taxonomies paged urls.

Hope this helps.


If you want to change it to the post type publication globally then use the pre_get_posts hook and add the following to your functions.php

add_action( 'pre_get_posts', function ( $query ) {
  if ( 'publication' === $query->query_vars['post_type'] && ! is_admin() ) {
    $query->set( 'posts_per_page', 5 );
} );

If you need it for only one custom query than the following answer will help you: https://stackoverflow.com/a/20905538/2043492

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.