• Hi Guys

    I want to show related posts, with the same taxonomy (artists) as the current post. In the realted post I dot want the current post to appear.

    I am also using a custom post type. (sculptures)

    This is the code i am using below, but it is showing the current post in the realted post and all post not only those with the taxonomy (artists”)

    Does anyone have a solution

    <div class=”related-posts”>
    <h3 class=”widget-title”>Related Posts</h3>

    </div>

Viewing 1 replies (of 1 total)
  • Richard

    (@richardcoffee)

    You don’t want to use get_the_term_list(). Use get_the_terms() instead.
    Take a close look at https://codex.www.ads-software.com/Class_Reference/WP_Query.

    Your query probably needs to look something like this:

    $args = array('post_type' => 'sculptures',
                  'post__not_in' => array($post->ID),
                  'tax_query'=>array(array('taxonomy'=>'artist',
                                           'field'=>'slug',
                                          'terms'=>get_the_terms($post->ID,'artist'))));
    $query = new WP_Query($args);
Viewing 1 replies (of 1 total)
  • The topic ‘display related post by taxonomy’ is closed to new replies.