我正在尝试为名为的自定义\\u post\\u类型重写urlwr_events
其中一个自定义的\\u分类术语来自event_type
add_action(\'init\', \'wr_events\');
function wr_events() {
register_taxonomy(
\'event_type\',
\'wr_event\',
array(
\'label\' => \'Types\',
\'singular_label\' => \'Typ\',
\'hierarchical\' => true,
\'query_var\' => true,
\'rewrite\' => array(\'slug\' => \'events\'),
)
);
$labels = array(
\'name\' => _x(\'Events\', \'post type general name\'),
\'singular_name\' => _x(\'Event\', \'post type singular name\')
);
$args = array(
\'labels\' => $labels,
\'public\' => true,
\'publicly_queryable\' => true,
\'show_ui\' => true,
\'query_var\' => true,
\'capability_type\' => \'post\',
\'hierarchical\' => false,
\'menu_position\' => null,
\'supports\' => array(\'title\',\'editor\',\'thumbnail\', \'excerpt\'),
\'rewrite\' => array(
//\'slug\' => \'event\',
\'slug\' => \'events/%event%\',
\'with_front\' => false
),
\'has_archive\' => \'events\'
);
register_post_type( \'wr_event\' , $args );
flush_rewrite_rules();
}
add_action(\'save_post\', \'save_details\');
add_filter(\'post_type_link\', \'events_permalink_structure\', 10, 4);
function events_permalink_structure($post_link, $post, $leavename, $sample)
{
if ( false !== strpos( $post_link, \'%event%\' ) ) {
$event_type_term = get_the_terms( $post->ID, \'event_type\' );
$post_link = str_replace( \'%event%\', array_pop( $event_type_term )->slug, $post_link );
}
return $post_link;
}
所以在我的例子中,我的分类术语是“研讨会”或“讲座”等。
url/events/lectures
或
url/events/workshops
列出我所有与此“类别”相关的帖子,
url/events
显示所有我的事件的自定义存档。->这正是我想要的,但是唯一不起作用的是自定义帖子本身的完整url…
url/events/lectures/post-name
- 抛出404!
知道为什么会这样吗?我的events_permalink_structure()
函数似乎工作正常,因为它以我想要的方式替换了我的permalinks。
我安装了“重写分析器”插件shows me “Regex为空”用于wr_event
.
我还尝试通过访问永久链接设置刷新重写规则。但没有任何影响。