$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>permalinks - Rename Custom Post Slug using taxonomy|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

permalinks - Rename Custom Post Slug using taxonomy

matteradmin8PV0评论

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 badges
Add a comment  | 

1 Answer 1

Reset to default 0

You'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 );
Post a comment

comment list (0)

  1. No comments so far