Answer the question
In order to leave comments, you need to log in
How to list matching taxonomies?
There is:
Custom type : service - list of services
Custom taxonomy :
vrachi - doctors for this service
Custom taxonomy : uslugi- categories for this service
In the service, I select data for two taxonomies at once: Service category and Doctor
which are selected only for those services that are tied to the current category?
I tried to go through all the posts of the current category in a loop, and get doctors for each post,
but in the end I get duplicate doctors, due to the fact that one doctor is tied to several services, it may be easier to add some kind of filter so that if the doctor has already been displayed, then do not show it again?
// параметры по умолчанию
$posts = get_posts( array(
'orderby' => 'date',
'order' => 'DESC',
'include' => array(),
'exclude' => array(),
'meta_key' => '',
'meta_value' =>'',
'post_type' => 'service',
'suppress_filters' => true, // подавление работы фильтров изменения SQL запроса
) );
foreach( $posts as $post ){
setup_postdata($post);
//получаем ID поста
$sadj = get_the_ID();
//выводим всех врачей этого поста
$cur_terms = get_the_terms( $sadj, 'vrachi' );
if( is_array( $cur_terms ) ){
foreach( $cur_terms as $cur_term ){
echo '<a href="'. get_term_link( $cur_term->term_id, $cur_term->taxonomy ) .'">'. $cur_term->name .'</a>,';
}
}
//выавыавыа
echo '<br/>';
}
wp_reset_postdata(); // сброс
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question