Skip to content

Instantly share code, notes, and snippets.

@Tabrisrp
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tabrisrp/85628f1e90880c04f3fb to your computer and use it in GitHub Desktop.
Save Tabrisrp/85628f1e90880c04f3fb to your computer and use it in GitHub Desktop.
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