Home Forums Front-end Issues Query with Meta_Query Not Working


Query with Meta_Query Not Working

  • I have a custom post type with a custom field. Here is the info on the custom field:

    • name = partner_type
    • type = Taxonomy
    • appearance = checkbox
    • value = term_id

    My query works fine until I include the “meta_query” with real term_id’s.

    'meta_query' = array(
                        'key'       => 'partner_type',
                        'value'     => array( $search['type'] ),
                        'compare'   => 'IN',

    Any idea on what I’m doing wrong? It returns no results. The sql looks like this:

    SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id ) WHERE 1=1 AND ( ( wp_postmeta.meta_key = 'partner_type' AND wp_postmeta.meta_value IN ('14') ) ) AND wp_posts.post_type = 'af_partners' AND ((wp_posts.post_status = 'publish')) GROUP BY wp_posts.ID ORDER BY wp_posts.post_title ASC LIMIT 0, 24

    By looking in the database, this is the post_meta for a record that should be in the results:


    Any help would be appreciated.

  • I resolved this by implementing what I read here. This is what I changed …

    'meta_query' = array(
                        'key'       => 'partner_type',
                        'value'     => '"'. $search['type'] .'"',
                        'compare'   => 'LIKE',
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.