我有3个自定义帖子类型设置,我已经创建了每个自定义的永久链接结构。我遇到的问题是,第三个自定义文章类型我与自定义固定链接设置,被用于之前的2WordPress的自定义帖子类型和自定义永久链接结构错误
例子:
- 分类
- 就业
- 赞助
以上是帖子类型,我将自定义的固定链接结构设置为(对于每个): /post_type/post_id/
现在,上面的顺序是他们设置的顺序和赞助承担所有这些。因此,例如:
/classified/100/
/employment/101/
/sponsorship/102/
以上都使用固定链接:
/sponsorship/100/
/sponsorship/101/
/sponsorship/102/
我在做什么错得到这个错误发生?这是一个永久链接结构错误吗?下面是我用来为每个创建自定义永久链接结构的代码。唯一的区别是,%c_id%更改为%e_id%和%s_id%的分类广告,雇佣和赞助。此外,对“分类广告”的引用分别改为就业和赞助。
add_action('init', 'classifieds_rewrite');
function classifieds_rewrite() {
global $wp_rewrite;
$queryarg = 'post_type=classifieds&p=';
$wp_rewrite->add_rewrite_tag('%c_id%', '([^/]+)', $queryarg);
$wp_rewrite->add_permastruct('classifieds', '/classifieds/%c_id%/', false);
}
add_filter('post_type_link', 'classifieds_permalink', 1, 3);
function classifieds_permalink($post_link, $id = 0) {
global $wp_rewrite;
$post = &get_post($id);
if (is_wp_error($post))
return $post;
$newlink = $wp_rewrite->get_extra_permastruct('classifieds');
$newlink = str_replace("%c_id%", $post->ID, $newlink);
$newlink = home_url(user_trailingslashit($newlink));
return $newlink;
}
感谢您的帮助! :)
我有: ' '改写'=> TRUE' ?? – fatwombat 2011-03-25 13:27:53
如果你使用''rewrite'=> array('slug'=>'YourSlug','with_front'=> true)'它会用你指定的slug重写你的帖子的固定链接。例如,如果您为您的分类文章添加''rewrite'=> array('slug'=>'classified','with_front'=> true)',您的链接将被重写为www.yoursite.com/classified/your -post-title取决于您在WP管理员中设置的额外永久链接结构。 – ckaufman 2011-03-25 13:42:14
是的,但我需要使用URL的第二部分的post_id。所以它需要/分类/ 124 /而不是/分类/ the-title-here/ 默认情况下有什么办法吗?因为我希望网站上的其他网页能够/ about /和/ contact/etc ...? – fatwombat 2011-03-25 14:02:45