There is a link structure for example site.ru/post/post_data/post_name/ how to make it so that in a post that is tied to the custom taxonomy "slider" the structure was site.ru/slider/post/post_data/post_name/? And all the other permalinks remained the same.

    1 answer 1

    It worked for me. The only negative is that I had to put in the links where there is no necessary category "news". And write a revrayt that would not give out 404 when you go to the page.

    add_filter('post_link', 'locale_permalink', 10, 3); add_filter('post_type_link', 'locale_permalink', 10, 3); function locale_permalink($permalink, $post_id, $leavename) { if (strpos($permalink, '%category_slider%') === FALSE) return $permalink; $post = get_post($post_id); if (!$post) return $permalink; if ($post->post_type != 'post') { return $permalink; } else { $terms = wp_get_object_terms($post->ID, 'category_slider'); if (!is_wp_error($terms) && !empty($terms) && is_object($terms[0])) $taxonomy_slug = $terms[0]->slug; else $taxonomy_slug = 'news'; return str_replace('%category_slider%', $taxonomy_slug, $permalink); } } add_filter('rewrite_rules_array','remove_bare_folder_rule'); function remove_bare_folder_rule( $rules ) { unset($rules['([^/]+)/?$']); return $rules; }