Support

Account

Home Forums Front-end Issues Query with Meta_Query Not Working

Helping

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(
                    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:

    a:1:{i:0;s:2:"14";}

    Any help would be appreciated.

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

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

The topic ‘Query with Meta_Query Not Working’ is closed to new replies.