0

I want to get a custom post type posts with the same tags. Here's what I'm trying:

$tags = get_the_terms( $post->ID, 'item-tags' );    //returns tags array correctly

if ($tags) {

    $tag_ids = array();
    foreach($tags as $single_tag){
        $tag_ids[] = $single_tag->term_id;
    }

    $args = array(
        'tag__in' => $tag_ids,  
        'post__not_in' => array($post->ID),                         
        'post_type' => 'item',                          
        'showposts' => 5,
        'ignore_sticky_posts' => 1
    );  

}

It does not return any post. If I remove tag_in and post_not_in then it returns all posts correctly. Is there anything wrong with the above arguments?

  • 1
    are 'item-tags' a custom taxonomy? – Eric Holmes Nov 25 '13 at 20:47
1

Re: my comment, I am assuming 'item_tags' are a custom taxonomy. tag__in only works for WP Core's Tag taxonomy. Replace your tag__in line with the following:

'tax_query' => array(
    array(
        'taxonomy' => 'item_tags',
        'field' => 'id',
        'terms' => $tag_ids
        )
    )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.