将其添加或替换到register\\u分类法(在functions.php中):
\'query_var\' => \'city\',
\'rewrite\' => true
然后将其附加到函数中。php
add_filter(\'post_link\', \'city_permalink\', 10, 3);
add_filter(\'post_type_link\', \'city_permalink\', 10, 3);
function city_permalink($permalink, $post_id, $leavename) {
if (strpos($permalink, \'%city%\') === FALSE) return $permalink;
// Get post
$post = get_post($post_id);
if (!$post) return $permalink;
// Get taxonomy terms
$terms = wp_get_object_terms($post->ID, \'city\');
if (!is_wp_error($terms) && !empty($terms) && is_object($terms[0])) $taxonomy_slug = $terms[0]->slug;
else $taxonomy_slug = \'not-rated\';
return str_replace(\'%city%\', $taxonomy_slug, $permalink);
}
Here 您可以找到更详细的描述。