Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Get a taxonomy's terms in posts with another taxonomy's term
<?php
$base_taxonomy = 'pays';
$term_id = '1';
$required_taxonomy = 'villes';
$required_terms = array();
$required_terms_id = array();
$objects_in_tax = get_objects_in_term( $term_id, $taxonomy );
if( !empty( $objects_in_tax ) ) {
if ( !is_wp_error( $objects_in_tax ) ) {
foreach ( $objects_in_tax as $post_id ) {
$required_terms = wp_get_object_terms( $post_id, $required_taxonomy );
if ( !empty( $required_terms ) {
if ( !is_wp_error( $required_terms ) ) {
foreach( $required_terms as $term ) {
$required_terms_id[] = $term->term_id;
}
$terms_id_unique = array_unique( $required_terms_id );
}
}
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.