0
嘿,这个人正在杀死我!Wordpress自定义帖子类型rewrite_tag在编辑器中不会被替换
我有一个自定义帖子类型叫'功能'。
它的档案页,目前通过可见: 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);
}
任何想法即时做错了什么?
Manged到谢天谢地解决它了! 好的,所以add_filter('post_type_link','cpt_url',1,3);是正确的,但我有它在前端添加(我知道) – joemcc 2013-05-14 10:36:35