【发布时间】:2019-05-06 18:36:53
【问题描述】:
我购买了一个主题,它具有自定义帖子类型talent,现在我正在尝试为该帖子类型创建一个自定义永久链接。
我已将此添加到functions.php
add_filter('post_link', 'talent_permalink', 99, 3);
add_filter('post_type_link', 'talent_permalink', 99, 3);
function talent_permalink($permalink, $post_id, $leavename) {
if (strpos($permalink, '%talent-cat%') === FALSE) return $permalink;
// Get post
$post = get_post($post_id);
if (!$post) return $permalink;
// Get taxonomy terms
$terms = wp_get_object_terms($post->ID, 'talent_category');
if (!is_wp_error($terms) && !empty($terms) && is_object($terms[0])) $taxonomy_slug = $terms[0]->slug;
else $taxonomy_slug = 'all';
return str_replace('%talent-cat%', $taxonomy_slug, $permalink);
}
我将%talent-cat% 添加到永久链接设置自定义结构中,但没有任何更改。
我想要什么
http://example.com/work/%talent-cat%/model/%postname%/
目前正在发生的事情
http://example.com/work/talent/%postname%/
我该如何解决?我希望我的代码永久链接函数以覆盖/优先任何插件。
【问题讨论】:
标签: wordpress