Sunday, May 29, 2022
HomeWordPress Developmenturl rewriting - Attempting so as to add array of paths to...

url rewriting – Attempting so as to add array of paths to publish permalink


Am making an attempt so as to add customized path to my article posttype

so my article path can be www.instance/parent-post-1/parent-post-2/the-actual-post

i attempted so as to add this code

/**
 * @param $post_link
 * @param $id
 * Добавить название категории продукта к ссылке
 * @return array|blended|string|string[]
 */
operate wpa_course_post_link($post_link, $id = 0)
{
    $publish = get_post($id);
    if ($publish instanceof WP_Post) {
        $guardian = get_field('mother and father', $post->ID) ?: [];
        $hyperlink = '';
        foreach ($guardian as $publish) {
            $hyperlink .= $post->post_name . "https://wordpress.stackexchange.com/";
        }
        if ($guardian) {
            $post_link = str_replace('%mother and father%/', $hyperlink, $post_link);
        }
    }
    return $post_link;
}

add_filter('post_type_link', 'wpa_course_post_link', 1, 3);

its works if the publish has just one guardian publish, but when the publish has greater than 1 guardian posts, it reveals 404

my CPT UI settings.
Customized rewrite slug -> articles/%mother and father%

easy methods to clear up this? thanks

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments