【发布时间】:2019-01-10 06:08:47
【问题描述】:
我有一个名为“references”的自定义帖子类型,并添加了一个函数,因此我可以将该类别用作永久链接的一部分。我像这样声明自定义 slug:
'slug' => '/references/%category%',
然后使用过滤器对其进行操作:
function change_post_link($post_link, $id = 0) {
$post = get_post($id);
if ($post->post_type == 'references') {
$terms = wp_get_object_terms($post->ID, 'category');
if ($terms) {
return str_replace('%category%', $terms[0]->slug, $post_link);
}
}
return $post_link;
}
这部分工作正常,我得到的 URL 像“/references/cars/the-red-one”。
但是现在我不能在“/references/cars”中拥有页面(默认类型),它只有在我没有为自定义帖子类型使用占位符时才有效。
您有什么想法可以解决这个问题吗? 'has_archive' 是假的。
谢谢!
【问题讨论】:
标签: wordpress