Support

Account

Home Forums Backend Issues (wp-admin) meta_query for taxonomy

Solved

meta_query for taxonomy

  • I have a “taxonomy” field for a post, which I’m using to link a post_type (article) to another post_type’s (course) categories.

    How can I use the meta_query to get all the articles in one course category?

    I’m using

     
    $args = array(
        'posts_per_page' => $num,
        'post_type'  => 'post',
        'meta_query' => array(
              'key' => 'segment',
              'value' => $segment_id,
              'compare' => 'LIKE',
            );
      );
      return get_posts( $args );
    

    where $segment_id is the tag_id.
    This works except it’s returning articles with category ID 3, as well as 34 because of the LIKE clause.

    
    'compare' => 'IN'
    

    Does not seem to work.

    I’m unfamiliar with how this is stored in the database.
    Any help is appreciated.

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘meta_query for taxonomy’ is closed to new replies.