我们有一个名为“评论”的自定义帖子,并根据为帖子选择的分类法(制造商)重命名URL。例如,如果选择了名为BENQ的MFG分类法,则帖子的URL将为
领域com/benq/postname不是域。com/reviews/postname/
我收到以下错误:警告:在/中调用的custom\\u post\\u type\\u link()缺少参数3/wp包括/类wp挂钩。php位于第288行,定义于//wp内容/主题/欠陷阱子主题/功能。php在线1192
功能如下:
add_filter(\'post_type_link\', \'custom_post_type_link\', 10, 2);
function custom_post_type_link($permalink, $post, $leavename) {
if (!gettype($post) == \'post\') {
return $permalink;
}
$url_components = parse_url($permalink);
$post_path = $url_components[\'path\'];
$post_path = trim($post_path, \'/\');
$post_name = explode(\'/\', $post_path);
$post_name = end($post_name);
if (!empty($post_name)) {
if ($post->post_type == \'reviews\') {
$terms = get_the_terms($post->ID, \'manufacturers\');
if (is_array($terms)) {
$term = array_pop($terms)->slug;
}
else {
$terms = get_the_terms($post->post_parent, \'manufacturers\');
if (is_array($terms)) {
$term = array_pop($terms)->slug;
}
else {
$term = \'review\';
}
}
$permalink = str_replace($post_path, \'\' . $term . \'/\' . $post_name . \'\', $permalink);
}
}
return $permalink;
}
你知道这个问题吗?