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