/[регион]
/[регион]/[округ]
/[регион]/[округ]/[город]
/[регион]/[округ]/[город]/[сообщество]
Я добавил фильтр для post_type_link и передаю функцию, обновляющую постоянные ссылки:
Код: Выделить всё
add_filter('post_type_link', array(&$this, 'rewriteCPTpermalinks'), 10, 2);
/**
* Rewrite Custom Post Type Permalinks
*
* @return void
*/
public function rewriteCPTpermalinks( $url, $post ){
global $wp_rewrite;
if ($post->post_type === 'counties') {
$regionObject = get_field('region', $post->ID );
// $url = get_the_permalink($regionObject->ID).$post->post_name;
$url = str_replace( '%region%', get_the_permalink($regionObject->ID), $url );
}
if ($post->post_type == 'cities') {
$countyObject = get_field('county', $post->ID);
$regionObject = get_field('region', $countyObject->ID );
$url = get_the_permalink($regionObject->ID).$countyObject->post_name.'/'.$post->post_name;
}
if ($post->post_type == 'communities') {
$cityObject = get_field('city_post', $post->ID);
$countyObject = get_field('county', $cityObject->ID);
$regionObject = get_field( 'region', $countyObject->ID );
$url = $regionObject->post_name.$countyObject->post_name.'/'.$cityObject->post_name.'/'.$post->post_name;
}
return $url;
}
Ключом к этому является то, чтобы все работало автоматически, без необходимости выбора. из пользовательской таксономии для каждого сообщения.
Я не уверен, что использую здесь правильный подход, но буду признателен за любую помощь.
Подробнее здесь: https://stackoverflow.com/questions/724 ... eld-values