Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Best4u Similar Posts
- function best4u_similar_posts($custom_post_type, $cuttom_taxonomy, $nr_posts) {
- global $post;
- $post_terms = array();
- $taxonomy = $cuttom_taxonomy;
- $terms = wp_get_post_terms($post->ID, $taxonomy);
- foreach ($terms as $term) {
- $post_terms[] = $term->term_id;
- }
- $posts_per_page = $nr_posts;
- $args = array(
- 'posts_per_page' => $posts_per_page,
- 'orderby' => 'date',
- 'post_status' => 'publish',
- 'post_type' => $custom_post_type,
- 'post__not_in' => array($post->ID),
- 'tax_query' => array(
- array(
- 'taxonomy' => $taxonomy,
- 'field' => 'id',
- 'terms' => $post_terms
- ),
- )
- );
- $all_posts = new WP_Query($args);
- return $all_posts->posts;
- }
Add Comment
Please, Sign In to add comment