I have set up a page with the URL slug "announcements"
I also have a custom post type with the rewrite set to the same name:
'rewrite' => array('slug' => 'announcements'),
This all works fine.
It gets tricky here though. On my announcements page, I have a loop, with a Prev and Next page link after the loop.
So if I try to go to page 2 , it looks for the URL /announcements/page/2/ which is a 404.
My guess is this is conflicting with the URLs for the custom post type.
Is there any workaround to make this functional, or am I stuck with changing either the CPT slug or the page name?
Also, the CPT is set to have no archive, if that makes a difference.
Here are the args for my CPT:
$args = array(
'label' => __( 'Announcements', 'textdomain' ),
'description' => __( 'Announcements Custom Post Type', 'textdomain' ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields'),
'taxonomies' => array( 'category', 'post_tag' ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 4,
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => false,
'exclude_from_search' => true,
'publicly_queryable' => true,
'menu_icon' => 'dashicon-here',
'capability_type' => 'post',
'rewrite' => array('slug' => 'announcements'),
);
Thanks
I have set up a page with the URL slug "announcements"
I also have a custom post type with the rewrite set to the same name:
'rewrite' => array('slug' => 'announcements'),
This all works fine.
It gets tricky here though. On my announcements page, I have a loop, with a Prev and Next page link after the loop.
So if I try to go to page 2 , it looks for the URL /announcements/page/2/ which is a 404.
My guess is this is conflicting with the URLs for the custom post type.
Is there any workaround to make this functional, or am I stuck with changing either the CPT slug or the page name?
Also, the CPT is set to have no archive, if that makes a difference.
Here are the args for my CPT:
$args = array(
'label' => __( 'Announcements', 'textdomain' ),
'description' => __( 'Announcements Custom Post Type', 'textdomain' ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields'),
'taxonomies' => array( 'category', 'post_tag' ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 4,
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => false,
'exclude_from_search' => true,
'publicly_queryable' => true,
'menu_icon' => 'dashicon-here',
'capability_type' => 'post',
'rewrite' => array('slug' => 'announcements'),
);
Thanks
How could there be a page 2 of the archives if you're not allowing archives?
This is also why it's working that you can have an actual page at that url and add a loop...you're adding that loop.
If you change your url "announcements" to something else you'll still see the first page of your cpt because presumably you've added your own custom loop.
You should not be rewriting your cpt permalinks to a page you have or create a page with the same url as your cpt permalink. It leads to confusion as you see in this case.
If you turn on the archive of this cpt, refresh your permalinks, you'll see that your content is no longer available.
Id suggest changing the slug of the page url to something else. That's the way Wordpress is intended to be used.