custom post types – Add_permastruct + $_SERVER[‘Request_uri’] is it working incorrectly?


Good afternoon. There is a record type, and two taxonomies go to it-geo and model. According to the requirements, it was necessary to rewrite the url in the form /%model%/%post_name%/%geo%/. In register_post_type, I rewritten everything using the same ad_permastruct, everything works well, up to the geo step.

Model/name post is a created record based on this structure, for example mers/sl300/msk-everything works.

global $wp_rewrite;

$current_url = ‘model/namepost/%geo%’;
$wp_rewrite->add_rewrite_tag(“%geo%”, ‘((^/)+)’, “geo=”);
$wp_rewrite->add_permastruct(‘geo’, $current_url);
add_filter(‘post_type_link’, ‘photo_permalink’, 10, 3);
function photo_permalink($permalink) {
return $permalink;
}

If I do not write the URL with my hands, but get the current ONE via $_SERVER (‘REQUEST_URI’), then I get the same url mers/sl300/msk – but it gives a 404 error immediately. I always reset permalinks

global $wp_rewrite;

$current_url = ”.$_SERVER(‘REQUEST_URI’). ‘/%geo%’;
$wp_rewrite->add_rewrite_tag(“%geo%”, ‘((^/)+)’, “geo=”);
$wp_rewrite->add_permastruct(‘geo’, $current_url);
add_filter(‘post_type_link’, ‘photo_permalink’, 10, 3);
function photo_permalink($permalink) {
return $permalink;
}