0

I made a shortcode to list form entry data that paginates using paginate_links(). I added this shortcode to a regular page and it works fine. If I click on page 2, it refreshes the page and adds the /page/2/ bit to my url: mydomain.com/slug/page/2/. Good, it works as expected.

Now, I moved this shortcode to a custom post type page (called self-studies) without doing anything to it. The new url is mydomain.com/self-studies/slug/. But when I go to page 2 it removes the /page/2/ and refreshes the page without it. It should have taken me to mydomain.com/self-studies/slug/page/2/. By the way, I have tried going directly to the correct link to ensure it was not a broken link, and it does the same thing, redirecting me to the page without the /page/2/. I also tried adding /page/2/ to other pages on the same post type that this shortcode does not exist on, and it does the same thing, so I know it has nothing to do with my paginate_links() code.

I have spent way too many hours trying to figure this out, so I come to you in hopes that someone can point me in the right direction.

Things I've tried:

  1. Changing my permalinks structure
  2. Changing all sorts of values in my custom post type args including 'has_archive' => true, removing the rewrite, etc (see what I have below), and yes I flushed the permalinks afterwards each time
  3. Verified that I don't have any pre_get_posts code that is conflicting
  4. Hooking into redirect_canonical and returning false
  5. Scouring the internet, searching for other questions on StackExchange, and even asking ChatGPT and Gemini (which is usually more counterproductive than helpful btw, lol)

My custom post type:

$args = [
    'label'                 => __( 'Self Studies', 'eri' ),
    'description'           => __( 'Self Studies', 'eri' ),
    'labels'                => $labels,
    'supports'              => [ 'title', 'editor', 'thumbnail', 'author', 'revisions', 'excerpt', 'comments' ],
    'taxonomies'            => [],
    'hierarchical'          => true,
    'public'                => true,
    'show_ui'               => true,
    'show_in_menu'          => true,
    'menu_position'         => 6,
    'menu_icon'             => 'dashicons-clipboard',
    'show_in_admin_bar'     => true,
    'show_in_nav_menus'     => true,
    'can_export'            => true,
    'has_archive'           => false,
    'exclude_from_search'   => true,
    'publicly_queryable'    => true,
    'query_var'             => $this->post_type,
    'capability_type'       => 'page',
    'show_in_rest'          => false,
    'rewrite'               => [ 'slug' => $this->post_type ],
];
register_post_type( $this->post_type, $args );

Any help is greatly appreciated. TIA!

1 Answer 1

0

Are you making changes to the query in the template at all? If you modify the main query you often have to include "Paged" parameter, as explained here: https://codex.wordpress.org/Pagination

If WP_Query is altering the main loop and the "paged" parameter is not set you'll need to add it with get_query_var(). This is so WordPress knows exactly what page it's on.

It's hard to know without seeing the code for the actual template you're using, but that's a potential path to explore.

1
  • Thanks for answering. No I'm not. As I stated, it has nothing to do with my template. It doesn't matter what is on the page, it simply won't work on any page with this post type. Additionally, I realized my default posts post type also do not allow /page/2/ to be added. Only default pages do. I've been reading that it should work on posts out of the box, so something is causing them to be turned off sitewide. I have been researching everywhere and can't figure it out.
    – Aristocles
    Commented Jul 24 at 14:28

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.