自定义帖子类型slu conflicts与另一种帖子类型冲突
问题描述:
这使我疯狂。自定义帖子类型slu conflicts与另一种帖子类型冲突
我有两个自定义文章类型
register_post_type('products',
array(
'labels' => array(
'name' => __('Products'),
'singular_name' => __('Product')
),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'products'),
)
);
register_post_type('markets',
array(
'labels' => array(
'name' => __('Markets'),
'singular_name' => __('Market')
),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'markets'),
)
);
和两个模板(归档products.php和归档markets.php)
的products
自定义类型的作品。存档页面正确显示,但单个页面不显示。如果我删除市场上的register_post_type
,则产品的单页工作。
但是,markets
类型的网址为www.website.com/products/a-market-post
这真的很奇怪,因为它使用产品帖子类型中的slu g。
有谁知道可能发生了什么?我刷新了固定链接页面1000次,并没有做任何事情。
干杯!
答
您错过了“分类法”。
而你不需要“重写”,因为你的slu remains不变。
function manufacturers_posts() {
$labels = array(
'name' => _x('Products', 'post type general name'),
'singular_name' => _x('Product', 'post type singular name'),
'add_new' => _x('Add new', 'book'),
'add_new_item' => __('Add new product'),
'edit_item' => __('Edit'),
'new_item' => __('יAdd new'),
'all_items' => __('Show all'),
'view_item' => __('Show'),
'search_items' => __('Search'),
'not_found' => __('No products found'),
'not_found_in_trash' => __('Trash is empty'),
'parent_item_colon' => '',
'menu_name' => 'Products'
);
$args = array(
'labels' => $labels,
'public' => true,
'supports' => array('title', 'editor', 'thumbnail', 'excerpt', 'comments', 'revisions', 'custom-fields', 'tags'),
'has_archive' => true,
'taxonomies' => array('post_tag')
);
register_post_type('manufacturers', $args);
}
function manufacturers_taxonomy() {
register_taxonomy(
'manufacturers_taxonomy', //The name of the taxonomy. Name should be in slug form (must not contain capital letters or spaces).
'manufacturers', //post type name
array(
'hierarchical' => true,
'label' => 'Products', //Display name
'query_var' => true,
'has_archive' => 'manufacturers',
'rewrite' => array(
'slug' => 'manufacturers-archive', // This controls the base slug that will display before each term
'with_front' => false // Don't display the category base before
)
)
);
}
add_action('init', 'manufacturers_taxonomy');
add_action('init', 'manufacturers_posts');
什么是您的永久链接结构? –
你在哪里放置代码?在一个函数在init钩子上触发? –
@MohammadAshiqueAli月份和名称 – Splurtcake