Last active
August 29, 2015 14:05
-
-
Save Tabrisrp/85628f1e90880c04f3fb to your computer and use it in GitHub Desktop.
Get a taxonomy's terms in posts with another taxonomy's term
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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