Guest User

Untitled

a guest
Jan 17th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. 'tax_query' => array(
  2. array(
  3. 'taxonomy' => 'city',
  4. 'field' => 'slug',
  5. 'terms' => array( nyc, boston, london ),
  6. )
  7. )
  8.  
  9. // get all terms in the taxonomy
  10. $terms = get_terms( 'city' );
  11. // convert array of term objects to array of term IDs
  12. $term_ids = wp_list_pluck( $terms, 'term_id' );
  13.  
  14. // proceed with tax query
  15. $args = array ('tax_query' => array(
  16. array(
  17. 'taxonomy' => 'city',
  18. 'field' => 'term_id',
  19. 'terms' => $term_ids,
  20. )
  21. )
  22. );
  23.  
  24. $city_posts = new WP_Query( $args );
  25.  
  26. $args = array ('tax_query' =>
  27. array(
  28. array(
  29. 'taxonomy' => 'city',
  30. //'field' => 'term_id', // <-- not needed, default
  31. //'terms' => $term_ids, // <-- not needed
  32. 'operator' => 'XXX' // Use a non-existing operator
  33. )
Add Comment
Please, Sign In to add comment