I have a custom post meta that contains array values
code:
update_post_meta($post_id,'custom_meta_key',array('val1','val2','val3','val4'));
Now I want to hook a call back to pre_get_posts to modify the query
code:
add_action('pre_get_posts','foo');
function foo ($q){
if ( ! $q->is_main_query() ) return;
if ( ! $q->is_post_type_archive() ) return;
if ( ! is_admin() ) {
$q->set('meta_query',array(
array(
'key' => 'custom_meta_key',
'value' => array('val1','val3'),
'compare' => 'IN'
)
));
}
remove_action( 'pre_get_posts','foo');
}
I want to only get the posts with the 'custom_meta_key' post meta having values of 'val1' or 'val3'
but the result is blank, the page doesn't return any items at all.
this must be because update_post_meta serializes the array upon save? Is what I am trying to achieve possible?