简而言之,我正在尝试获取自定义帖子类型类别以显示“项目项目”的位置,如您所见HERE
我认为它与我注册自定义帖子类型的方式有关,例如在此代码中:
<?php
add_action( 'init', 'register_posts' );
function register_posts() {
register_post_type( 'team_post',
array(
'labels' => array(
'name' => __( "Team" ,"um_lang"),
'singular_name' => __( "Team" ,"um_lang")
),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => "project_item", 'with_front' => TRUE),
'supports' => array('title','editor','thumbnail','page-attributes')
)
);
register_post_type( 'project_post',
array(
'labels' => array(
'name' => __( "Projects","um_lang"),
'singular_name' => __( "Project" ,"um_lang")
),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => "project_item", 'with_front' => TRUE),
'supports' => array('title','editor','thumbnail','page-attributes')
)
);
register_taxonomy('project_category',array (
0 => 'project_post',
),array( 'hierarchical' => true, 'label' => __('Projects Category',"um_lang"),'show_ui' => true,'query_var' => true,'singular_label' => __('Projects Category',"um_lang")) );
}
?>
答案 0 :(得分:0)
这告诉wordpress将文本project_item插入到slug中,这就是正在发生的事情:
'rewrite' => array('slug' => "project_item", 'with_front' => TRUE)
这就是插入project_item的值:
'rewrite' => array('slug' => "%project_item%", 'with_front' => TRUE)
答案 1 :(得分:0)
我明白了。我安装了这个插件:https://wordpress.org/plugins/custom-post-type-permalinks/
然后我使用了特定的自定义帖子类型类别名称(%project_category%),而不是使用%category%(不起作用)
答案 2 :(得分:0)
试试这个:
global $wp_rewrite;
$movies_structure = '/movies/%year%/%monthnum%/%day%/%movies%';
$wp_rewrite->add_rewrite_tag("%movies%", '([^/]+)', "movies=");
$wp_rewrite->add_permastruct('movies', $movies_structure, false);
返回链接:
domain.com/movies/movie_name