尝试首次添加到%event_id%
给你的鼻涕虫:
$args = array(
\'labels\' => $labels,
\'public\' => true,
\'hierarchical\' => false,
\'rewrite\' => array(
\'with_front\' => false,
\'slug\' => \'news/events/%event_id%/%postname%\'
),
\'supports\' => array( \'title\', \'editor\', \'thumbnail\' )
);
register_post_type(\'events\',$args);
然后将筛选器添加到单个事件预链接:
add_filter(\'post_type_link\', \'custom_event_permalink\', 1, 3);
function custom_event_permalink($post_link, $id = 0, $leavename) {
global $wp_rewrite;
$post = &get_post($id);
if ( is_wp_error( $post ) || \'events\' != $post->post_type)
return $post_link;
$newlink = $wp_rewrite->get_extra_permastruct(\'events\');
$newlink = str_replace("%event_id%", $post->ID, $newlink);
$newlink = home_url(user_trailingslashit($newlink));
return $newlink;
}
这应该能奏效,但它是
untested. 并确保刷新重写规则。