嘿,这个杀了我!
我有一个名为“功能”的自定义帖子类型。
它的存档页面当前可见于: mysite.com/features/
目前单一功能位于: mysite.com/features/single-post/
但是我希望在以下位置提供单一功能: mysite.com/feautres/23423/single-post/
即 $post->ID 被添加到 url。
这在前端工作并正确重写,但是在 wordpress 管理员中它显示链接为: mysite.com/feautres/%cpt_id%/single-post/
这就是我到目前为止的代码;
add_filter('post_type_link', 'cpt_url', 1, 3);
function cpt_url($post_link, $id = 0, $leavename) {
global $wp_rewrite;
$post = &get_post($id);
if ( is_wp_error( $post ) )
return $post;
$newlink = $wp_rewrite->get_extra_permastruct('features');
$newlink = str_replace("%postid%", $post->ID, $newlink);
$newlink = home_url(user_trailingslashit($newlink));
return $newlink.$post->post_name.'/';
}
add_action('init', 'add_custom_rewrites');
function sumo_add_custom_rewrites(){
global $wp_rewrite;
//rewrites for feature
$queryarg = 'post_type=features&p=';
$wp_rewrite->add_rewrite_tag('%postid%', '([^/]+)', $queryarg);
$wp_rewrite->add_permastruct('features', '/features/%postid%', false);
}
知道我做错了什么吗?