I'm an attempting to query a meta value (array) of user IDs:

$meta_query = [
            'key'       => '_votes_round_2',
            'value'     => $current_user->ID,
            'type'      => 'NUMERIC',
            'compare'   => 'IN'

I'm pretty sure that I'm going the wrong way about this as I'm not getting any results and see the following value in my database:

_votes_round_2 | a:1:{i:0;i:1;}

How can I correctly meta_query to return the post if the current user ID is in the post meta array with key '_votes_round_2'?

  • a:1:{i:0;i:1;} is serialized. What we see here is the non-empty array of size 1 byte containing integral 0 at the first key and integral 1 at the second. If you are writing a custom function, use the unserialize PHP function to get the data in a readable format. – Max Yudin Mar 22 '17 at 13:02
  • Thanks @Max Yudin. Is there a better way to store this data that you would recommend? I'm using 'update_post_meta' which I guess is serializing the value for me. I want to store an array of user IDs in this single meta value if possible. – Kevin Nugent Mar 22 '17 at 13:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.