通过添加过滤器和构建永久链接来解决此问题。首先,忘记pastebin代码,只需创建一个post类型和所需的TaxO,然后添加过滤器:
add_filter(\'post_link\', \'territorio_permalink\', 10, 3);
add_filter(\'post_type_link\', \'territorio_permalink\', 10, 3);
function territorio_permalink($permalink, $post_id, $leavename) {
if (strpos($permalink, \'%territorio%\') === FALSE) return $permalink;
// Get post
$post = get_post($post_id);
if (!$post) return $permalink;
// Get taxonomy terms
$terms = wp_get_object_terms($post->ID, \'territorio\');
if (!is_wp_error($terms) && !empty($terms) && is_object($terms[0]))
$taxonomy_slug = $terms[0]->slug.\'/\'.$terms[1]->slug; //build here
else $taxonomy_slug = \'not-yet\';
return str_replace(\'%territorio%\', $taxonomy_slug, $permalink);
}
在帖子类型创建中使用:
\'rewrite\' => array( \'slug\' => \'anything-you-want/%territorio%\',\'with_front\' => false),
注意:如果您想要更深入的链接,您的构建应该更深入:
$taxonomy_slug = $terms[0]->slug.\'/\'.$terms[1]->slug.\'/\'.$terms[2]->slug;