admin管理员组文章数量:1122832
struggling as well with custom url rewriting for custom post type taxonomies.
Here is my requirement:
domain/mycpt_category/postname/
It's well documented here and in several SE threads removing the CPT basename so that the resulting permalink is:
domain/postname/
And I am able to construct the permalink such as:
domain/cpt-basename/cpt_category/postname (following this solution )
What I am really trying to achieve is removing the custom post type slug but keep its related taxonomy category so my link would be:
domain/mycpt_category/postname/
Thanks for you much appreciated help on this.
struggling as well with custom url rewriting for custom post type taxonomies.
Here is my requirement:
domain/mycpt_category/postname/
It's well documented here and in several SE threads removing the CPT basename so that the resulting permalink is:
domain/postname/
And I am able to construct the permalink such as:
domain/cpt-basename/cpt_category/postname (following this solution )
What I am really trying to achieve is removing the custom post type slug but keep its related taxonomy category so my link would be:
domain/mycpt_category/postname/
Thanks for you much appreciated help on this.
Share Improve this question asked Mar 21, 2016 at 13:21 Lorenzo BeltrameLorenzo Beltrame 114 bronze badges1 Answer
Reset to default 0When registering your custom post type have you tried to disable with_front in your rewrite array? For example, using an example for the post type book:
add_action( 'init', 'codex_book_init' );
/**
* Register a book post type.
*
* @link http://codex.wordpress.org/Function_Reference/register_post_type
*/
function codex_book_init() {
$labels = array(
'name' => _x( 'Books', 'post type general name', 'your-plugin-textdomain' ),
'singular_name' => _x( 'Book', 'post type singular name', 'your-plugin-textdomain' ),
'menu_name' => _x( 'Books', 'admin menu', 'your-plugin-textdomain' ),
'name_admin_bar' => _x( 'Book', 'add new on admin bar', 'your-plugin-textdomain' ),
'add_new' => _x( 'Add New', 'book', 'your-plugin-textdomain' ),
'add_new_item' => __( 'Add New Book', 'your-plugin-textdomain' ),
'new_item' => __( 'New Book', 'your-plugin-textdomain' ),
'edit_item' => __( 'Edit Book', 'your-plugin-textdomain' ),
'view_item' => __( 'View Book', 'your-plugin-textdomain' ),
'all_items' => __( 'All Books', 'your-plugin-textdomain' ),
'search_items' => __( 'Search Books', 'your-plugin-textdomain' ),
'parent_item_colon' => __( 'Parent Books:', 'your-plugin-textdomain' ),
'not_found' => __( 'No books found.', 'your-plugin-textdomain' ),
'not_found_in_trash' => __( 'No books found in Trash.', 'your-plugin-textdomain' )
);
$args = array(
'labels' => $labels,
'description' => __( 'Description.', 'your-plugin-textdomain' ),
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'book', 'with_front' => false ),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' )
);
register_post_type( 'book', $args );
}
However, the above example does not incorporate your rewrites mentioned so be sure to adjust your rewrite args to suit.
本文标签: Remove custom post type slug but keep related category taxonomy permalink
版权声明:本文标题:Remove custom post type slug but keep related category taxonomy permalink 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736292660a1928981.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论