Php 自定义post类型slug与另一个post类型冲突
这让我快发疯了 我有两种自定义的帖子类型Php 自定义post类型slug与另一个post类型冲突,php,wordpress,Php,Wordpress,这让我快发疯了 我有两种自定义的帖子类型 register_post_type( 'products', array( 'labels' => array( 'name' => __( 'Products' ), 'singular_name' => __( 'Product' ) ), 'public' => true, 'has_archive' =
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'),
)
);
和两个模板(archive-products.php和archive-markets.php)
产品
自定义类型有效。存档页面显示正确,但单个页面不显示。如果我删除市场的register\u post\u类型
,则产品的单个页面将正常工作
然而,markets
类型的url是www.website.com/products/a-market-post
,这非常奇怪,因为它使用了products post类型中的slug
有人知道会发生什么吗?我已经刷新了permalinks页面1000次,但这没有任何作用
干杯 您缺少“分类法”。
你不需要“重写”,因为你的鼻涕虫是一样的
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 hook上激活的函数内?@MohammadAshiqueAli Month和name@NathanDawson我已经尝试过直接运行functions.php,也尝试过在init上启动的函数中运行