How to implement a different permalink structure for custom post type?
-
20-05-2021 - |
题
Tried to use this plugin, but it doesn't seem to be working: https://wordpress.org/plugins/custom-post-type-permalinks/
I'm setting a permalink structure for by blog posts in settings>permalinks like so: /blog/%postname%
I also have a custom post type called "project", where I want the structure to be /our-work/%postname
, but instead the /blog
part gets prepended here too. How can I keep a separate permalink structure for this custom post type?
Here's the register_post_type
function:
register_post_type('project', array(
'public' => true,
'custom' => true,
'show_ui' => true,
'supports' => array('title','editor','revisions'),
'labels' => array(
'name' => 'Projects',
'singular_name' => 'Project',
'add_new_item' => 'Add New Project',
'edit_item' => 'Edit Project'
),
'menu_icon' => 'dashicons-portfolio',
'show_ui' => true,
'show_in_menu' => true,
'show_in_rest' => true,
'rewrite' => array(
'slug' => 'our-work',
'with_front' => true
),
'has_archive' => true,
'show_in_graphql' => true,
'graphql_single_name' => 'project',
'graphql_plural_name' => 'projects',
'cptp_permalink_structure' => '%post_id%'
));
解决方案
Just set the with_front
argument to false
:
register_post_type( 'project', array(
... your args.
'rewrite' => array(
'slug' => 'our-work',
'with_front' => false
),
... your args.
) );