Answer the question
In order to leave comments, you need to log in
How to display the necessary terms of the post taxonomy?
Good day to all. I'm racking my brains on how to derive the necessary taxonomy terms.
Now
<?php
$cur_terms = get_the_terms( $postID->ID, 'wpsl_store_category');
// var_dump($cur_terms);
if( is_array( $cur_terms ) ){
foreach( $cur_terms as $cur_term ){
echo $cur_term->name;
}
}
?>
Answer the question
In order to leave comments, you need to log in
get_the_terms()
gets the terms related to the current entry. If you have "Free" and "Public" checked, the function will return them too. There are no arguments in this function that allow you to exclude terms from the selection at the time of the query to the database
. You can exclude the necessary terms when displaying them in the front, but the principle by which you want to do this is not entirely clear. The easiest way is to check for existence in an arbitrary array
$cur_terms = get_the_terms( $postID->ID, 'wpsl_store_category' );
$not_allowed = [ 'Бесплатно', 'Государственное' ];
if( is_array( $cur_terms ) ) {
foreach( $cur_terms as $cur_term ) {
if ( !in_array( $cur_term->name, $not_allowed ) ) {
echo $cur_term->name;
}
}
}
You can display the ones you need through an array or exclude those that do not need to be displayed. All details here: https://wp-kama.ru/function/get_taxonomies
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question