Matching Serialized Arrays with meta_query

I just figured out myself how to do it

Take a look at this example:

$args = array();
$args['relation'] = 'OR';
foreach ( $tag_ids as $t ) {
    $args[] = array(
        'key'     => 'afz_entry_tags',
        'value'   => serialize( strval( $t->id ) ),
        'compare' => 'LIKE'
    );
}

$query->set( 'meta_query', $args );

I am getting $tag_ids with a normal get_results.

Then i create the first item of the array for meta_query in order to define the OR i need.

Then i iterate through the collection of objects i received from get_results and create as many arrays for the meta_query as i need.

It works like a charm.

Leave a Comment