Фильтр (exlude) таксономии из массива по главному родителю
использую get_the_category($post->ID, 'category') и получаю ( лишние строки убрал )
убить категорию (категории) по id не проблема, а как убить по высшему родителю?
Array ( [0] => WP_Term Object ( [term_id] => 77 [term_taxonomy_id] => 77 [taxonomy] => category [parent] => 78 [cat_ID] => 77 [category_parent] => 78 ) [1] => WP_Term Object ( [term_id] => 96 [term_taxonomy_id] => 96 [taxonomy] => category [parent] => 42 [cat_ID] => 96 [category_parent] => 42 ) )
Ломаю голову: как отсечь из вывода все категории что принадлежат [category_parent] => 78
можно ли как-то сделать на подобие ?
get_the_category($post->ID , array(
'taxonomy' =>'category',
'Excludes' => {[category_parent] => 78'}
));
хочу просто убивать с массива таксономии (и инфу) которые являются дочерними к [category_parent] => 78 - все остальное должно идти как обычно
должно просто остаться
Array ( [0] => WP_Term Object ( [term_id] => 96 [term_taxonomy_id] => 96 [taxonomy] => category [parent] => 42 [cat_ID] => 96 [category_parent] => 42 ) )
сейчас юзаю
///////Example usage//////////
//get object terms for $post->ID with taxonomies categories and tags,
//args set as fields all and exclude term with id 1
///////Filter function//////////
function wp_get_object_terms_exclude_filter($terms, $object_ids, $taxonomies, $args) {
//if exclude is set and fields is set to all go
if(isset($args['exclude']) && $args['fields'] == 'all') {
//loop through terms
foreach($terms as $key => $term) {
//loop through exclude terms
foreach($args['exclude'] as $exclude_term) {
//if exlude term matches current object term unset
if($term->term_id == $exclude_term) {
unset($terms[$key]);
}
}
}
}
//reset keys, because of unset.
$terms = array_values($terms);
return $terms;
}
add_filter('wp_get_object_terms', 'wp_get_object_terms_exclude_filter', 10, 4);
в сингле
$term = wp_get_object_terms(
$post->ID,
array(
'category',
'post_tag'
),
array(
'fields' => 'all',
'exclude' => array(78,77)
)
);