Hello guys,
I’ve been researching this issue for a few hours now and haven’t been able to figure this out.
This is what’s happening: when I use the pagination to go to page 2 it shows a blank page.
I have my blog using the slug name:
domain.com/blog
And using CPT UI, I’m using the following Custom Rewrite Slug:
blog
Code:
function cptui_register_my_cpts_article() {
    /**
* Post Type: Articles.
*/
$labels = [
“name” => esc_html__( “Articles”, “custom-post-type-ui” ),
“singular_name” => esc_html__( “Article”, “custom-post-type-ui” ),
];
    $args = [
“label” => esc_html__( “Articles”, “custom-post-type-ui” ),
“labels” => $labels,
“description” => “”,
“public” => true,
“publicly_queryable” => true,
“show_ui” => true,
“show_in_rest” => true,
“rest_base” => “”,
“rest_controller_class” => “WP_REST_Posts_Controller”,
“rest_namespace” => “wp/v2”,
“has_archive” => false,
“show_in_menu” => true,
“show_in_nav_menus” => true,
“delete_with_user” => false,
“exclude_from_search” => false,
“capability_type” => “post”,
“map_meta_cap” => true,
“hierarchical” => false,
“can_export” => false,
“rewrite” => [ “slug” => “blog”, “with_front” => true ],
“query_var” => true,
“supports” => [ “title”, “editor”, “thumbnail”, “excerpt”, “related” ],
“show_in_graphql” => false,
];
    register_post_type( “article”, $args );
}
add_action( ‘init’, ‘cptui_register_my_cpts_article’ );
I know that having the same name in both Custom Rewrite Slug and Page Slug can result in pagination issues. If I change the Page Slug to something else, it works perfectly. But I really need to be the same, I know that it is possible, I already seen many blogs using the url domain.com/blog/articlename for articles.
Any idea how to do it, please? 🙂
Thanks in advance.
[ad_2]
You can’t have a page with the same url as your CPT slug, as you’ve found. Instead of using a page to show all blog posts, you can make use of an archive template for your custom post type.
Then the archive template will handle showing all of your CPT entries at the `domain.com/blog` url you set in your CPT code, and any single CPT entries will have a url like `domain.com/blog/somepost` because blog is the CPT they’re in.
Your theme may already have a generic archive template that works just fine. If not, you’ll have to set one up.
Here’s a couple of docs for classic theme PHP CPT archive templates:
*
*
If you have a newer block/FSE theme you can add a new “Archive: Blog” template for your blog custom post type in the site editor, and set it up in there.