Guest User

Untitled

a guest
Mar 17th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. $current_user = wp_get_current_user();
  2.  
  3. $current_user_posts = get_posts(array(
  4. 'author' => $current_user->ID,
  5. 'posts_per_page' => -1
  6. );
  7.  
  8. $current_user_terms = array();
  9. foreach ($current_user_posts as $user_post) {
  10. $user_terms = wp_get_post_terms($user_post->ID, 'custom_tax', array("fields" => "ids"));
  11. foreach ($user_terms as $user_term ) {
  12. if (!in_array($user_term->term_id, $current_user_terms))
  13. $current_user_terms[] = $user_term->term_id;
  14. }
  15. }
  16.  
  17. $your_query = new WP_Query( array(
  18. 'tax_query' => array(
  19. array(
  20. 'taxonomy' => 'custom_tax',
  21. 'field' => 'term_id',
  22. 'terms' => $current_user_terms,
  23. ),
  24. ));
  25. if ( $the_query->have_posts() ) { ..
Add Comment
Please, Sign In to add comment