admin管理员组文章数量:1122846
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/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/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/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:
- Changing my permalinks structure
- Changing all sorts of values in my custom post type args including
'has_archive' => true
, removing therewrite
, etc (see what I have below), and yes I flushed the permalinks afterwards each time - Verified that I don't have any
pre_get_posts
code that is conflicting - Hooking into
redirect_canonical
and returningfalse
- 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!
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:
- Changing my permalinks structure
- Changing all sorts of values in my custom post type args including
'has_archive' => true
, removing therewrite
, etc (see what I have below), and yes I flushed the permalinks afterwards each time - Verified that I don't have any
pre_get_posts
code that is conflicting - Hooking into
redirect_canonical
and returningfalse
- 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!
Share Improve this question edited Jul 19, 2024 at 21:51 Aristocles asked Jul 19, 2024 at 21:28 AristoclesAristocles 1397 bronze badges1 Answer
Reset to default 0Are 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.
本文标签: phpCustom post type removing page2 from URL when trying to access it
版权声明:本文标题:php - Custom post type removing page2 from URL when trying to access it 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736300092a1930695.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论