I am trying to query the meta data _players
in my database which has serialized arrays as values the data is inserted via a wordpress meta box.
I thought I could just do a LIKE
comparison on a serialized version of the get_post_meta
but the results only show posts with that exact serialized string.
Get the meta data
$keyGUID = serialize(get_post_meta($postID, "_players", true));
// returns "a:2:{i:0;s:8:"DC242003";i:1;s:8:"BY523643";}"
Build query arguements
$types = get_post_types();
$args = array(
"post_type" => $types,
"post_status" => "publish",
"posts_per_page" => $posts,
"meta_query" => array(
array(
"key" => "_players",
"value" => $keyGUID,
"compare" => "LIKE"
)
)
);
$myposts = get_posts($args);
And the database records I am querying
How do I modify my script to process the post meta so it queries each GUID?
What I want to happen is for posts to be displayed if either of the values exist not if they both exist
1 Post for BY523643
2 Posts for DC242003
"compare" => "IN"
and see what they returns you? You can't really search a serialized array, you really need to store the data individually or get all the data out first, unserialze and search that... – Simon Pollard