meta_query key value from array

I don’t know if you can get one array to compare to the other directly, but you can create a loop to set up a meta_query array that will check for each of the IDs within the field separately:

$tag_ids = wp_get_post_tags( $post->ID, array( 'fields' => 'ids' ) );

$meta_query = array('relation' => 'OR');

foreach ($tags_ids as $tag_id) {
    $meta_query[] = array(
        'key' => 'gametags',
        'value' => $tag_id,
        'compare' => 'IN'
    );
}

$reviewArgs = array(
   'post_type' => 'game',
   'meta_query' => $meta_query
);

Note: this could produce errors if no tags are set for the post so you might want to add some alternative handling for that case.

EDIT: try this to test for the exact matches later…

$review_query = new WP_Query( $reviewArgs ); 
while( $review_query->have_posts() ) { 
    $review_query->the_post(); 
    global $post; $checkmatch = false;
    $gametags = get_post_meta($post->ID,'gametags');
    if (!is_array($gametags)) {$gametags = explode(',',$gametags);}
    foreach ($tags_ids as $tag_id) {
        if (in_array($tag_id,$gametags)) {$checkmatch = true;}
    }
    if ($checkmatch) {
         // echo output
    }
}

Leave a Comment