Guest User

Untitled

a guest
Dec 17th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. <?php
  2.  
  3. // Best4u Similar Posts
  4. function best4u_similar_posts($custom_post_type, $cuttom_taxonomy, $nr_posts) {
  5. global $post;
  6. $post_terms = array();
  7. $taxonomy = $cuttom_taxonomy;
  8. $terms = wp_get_post_terms($post->ID, $taxonomy);
  9.  
  10. foreach ($terms as $term) {
  11. $post_terms[] = $term->term_id;
  12. }
  13.  
  14. $posts_per_page = $nr_posts;
  15. $args = array(
  16. 'posts_per_page' => $posts_per_page,
  17. 'orderby' => 'date',
  18. 'post_status' => 'publish',
  19. 'post_type' => $custom_post_type,
  20. 'post__not_in' => array($post->ID),
  21. 'tax_query' => array(
  22. array(
  23. 'taxonomy' => $taxonomy,
  24. 'field' => 'id',
  25. 'terms' => $post_terms
  26. ),
  27. )
  28. );
  29. $all_posts = new WP_Query($args);
  30.  
  31. return $all_posts->posts;
  32. }
Add Comment
Please, Sign In to add comment