1

EDIT. I found the culprit causing my issue. I had the following code to change the pagination slug to "sida" to reflect the site language. It works well for blog posts, but it does not work for custom post types. If anyone knows how I can get custom pagination slug for all post types, please chip in!

// Change pagination slug
function bb2_pagination_slug() {
  global $wp_rewrite;  // Get the global wordpress rewrite-rules/settings

  // Change the base pagination property which sets the wordpress pagination slug.
  $wp_rewrite->pagination_base = "sida";
}
add_action( 'init', 'bb2_pagination_slug' );

Original question:

I have a custom post type archive which works well, except when trying to go to the next page in pagination I get a 404. I can't figure out what the problem is.

I had a page with the same name as my custom post type. I removed this since I thought it might have caused the issue, but it did not help. I have flushed my rewrite rules.

If I turn of pretty permalinks it works.

The archive exists at:

myproject.dev/om/vd-presenterar

The next page should be reachable at

myproject.dev/om/vd-presenterar/sida/2

The paginated page does exist, I can reach it with the following URL

myproject.dev/index.php?post_type=vd_presents&paged=2

which redirects to (I don't know how this works or why it does this):

myproject.dev/sida/2/?post_type=vd_presents

Here is relevant part of my custom post type code:

$rewrite = array(
    'slug'                => 'om/vd-presenterar',
    'with_front'          => false,
    'pages'               => true,
    'feeds'               => true,
);
$args = array(
    'labels'              => $labels,
    'supports'            => array( 'title', 'editor'),
    'taxonomies'          => array(''),
    'hierarchical'        => false,
    'public'              => true,
    'show_ui'             => true,
    'show_in_menu'        => true,
    'menu_position'       => 7,
    'show_in_admin_bar'   => true,
    'show_in_nav_menus'   => true,
    'can_export'          => true,
    'has_archive'         => true,
    'exclude_from_search' => false,
    'publicly_queryable'  => true,
    'rewrite'             => $rewrite,
    'capability_type'     => 'post',
);
register_post_type( 'vd_presents', $args );
  • 1
    I cannot help with rewrite rules, but just a basic check: This is inside an init hook, and you have flushed your permalink? – Pieter Goosen Jul 21 '15 at 9:25
  • Yes! The custom post type is registered with: add_action( 'init', 'cpt_vd_presents', 0 ); Also flushed permalink rules to many times now! :) – Johan Dahl Jul 21 '15 at 9:56
  • 1
    The pagination slug code you have shouldn't be - AFAIK - the issue. Try lowering the priority for it - add_action( 'init', 'bb2_pagination_slug', 1 );. Inspect your rewrite rules with the Monkeyman Rewrite Analyzer, maybe it will give you clarity on this. Be sure you have successfully flushed the rules and do it again to be certain, maybe try deleting/backing up your .htaccess and regenerating it. – Nicolai Jul 21 '15 at 12:03
  • I've just seen in your comment that you are registering the post type with priority 0, you should set it up in a way that the pagination slug rewrite happens before registering the post type. – Nicolai Jul 21 '15 at 12:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.