admin管理员组文章数量:1130349
We have a custom posts called "Reviews" and rename the URL based on a taxonomy (manufacturers) selected for the post. For example if the MFG taxonomy called BENQ is selected the URL for the post will be
domain/benq/postname not domain/reviews/postname/
I'm getting this error: Warning: Missing argument 3 for custom_post_type_link(), called in /../wp-includes/class-wp-hook.php on line 288 and defined in /../wp-content/themes/understrap-child-theme/functions.php on line 1192
Here is the function:
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;
}
Any idea of the issue?
We have a custom posts called "Reviews" and rename the URL based on a taxonomy (manufacturers) selected for the post. For example if the MFG taxonomy called BENQ is selected the URL for the post will be
domain/benq/postname not domain/reviews/postname/
I'm getting this error: Warning: Missing argument 3 for custom_post_type_link(), called in /../wp-includes/class-wp-hook.php on line 288 and defined in /../wp-content/themes/understrap-child-theme/functions.php on line 1192
Here is the function:
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;
}
Any idea of the issue?
Share Improve this question edited Nov 11, 2018 at 11:41 cameronjonesweb 9201 gold badge12 silver badges16 bronze badges asked Nov 11, 2018 at 6:05 RWGRWG 113 bronze badges1 Answer
Reset to default 0You're passing 3 arguments to your function ($permalink, $post, $leavename), but you're only specifying that it has 2 when you're adding the filter (the last parameter to add_filter). Change your add_filter call to this:
add_filter( 'post_type_link', 'custom_post_type_link', 10, 3 );
We have a custom posts called "Reviews" and rename the URL based on a taxonomy (manufacturers) selected for the post. For example if the MFG taxonomy called BENQ is selected the URL for the post will be
domain/benq/postname not domain/reviews/postname/
I'm getting this error: Warning: Missing argument 3 for custom_post_type_link(), called in /../wp-includes/class-wp-hook.php on line 288 and defined in /../wp-content/themes/understrap-child-theme/functions.php on line 1192
Here is the function:
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;
}
Any idea of the issue?
We have a custom posts called "Reviews" and rename the URL based on a taxonomy (manufacturers) selected for the post. For example if the MFG taxonomy called BENQ is selected the URL for the post will be
domain/benq/postname not domain/reviews/postname/
I'm getting this error: Warning: Missing argument 3 for custom_post_type_link(), called in /../wp-includes/class-wp-hook.php on line 288 and defined in /../wp-content/themes/understrap-child-theme/functions.php on line 1192
Here is the function:
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;
}
Any idea of the issue?
Share Improve this question edited Nov 11, 2018 at 11:41 cameronjonesweb 9201 gold badge12 silver badges16 bronze badges asked Nov 11, 2018 at 6:05 RWGRWG 113 bronze badges1 Answer
Reset to default 0You're passing 3 arguments to your function ($permalink, $post, $leavename), but you're only specifying that it has 2 when you're adding the filter (the last parameter to add_filter). Change your add_filter call to this:
add_filter( 'post_type_link', 'custom_post_type_link', 10, 3 );
本文标签: permalinksRename Custom Post Slug using taxonomy
版权声明:本文标题:permalinks - Rename Custom Post Slug using taxonomy 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749192463a2330401.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论