I am doing a
WP_Query trying to filter out the posts by Metadata.
$args = array( 'ignore_sticky_posts'=> 1, 'post_type' => 'post_projects', 'post_status' => 'publish', 'posts_per_page' => $nr_posts, 'meta_query' => array( 'relation' => 'OR', array( 'key' => 'wpl_goal_amount', 'value' => 100, 'compare' => '!=', ), array( 'key' => 'wpl_location', 'value' => 'Europe', 'compare' => '=', ), ), );
I am testing this out with two posts. One of them has "Europe" in it's array of locations, but whenever I run this, it doesn't come up with anything.
I am using Option Tree to save the Meta-data, and as mentioned in a previous answer, it stores serialized the post meta-data (by Wordpress' default), and in combination with that and another post, I found that there are two ways to query the serialized data. The first is more convenient, but more of a jerry-rig, and the second is more proper, but difficult:
array( 'key' => 'wpl_location', 'value' => '"' . $my_value . '"', 'compare' => 'LIKE' ),
Compared to the better but more difficult:
array( 'key' => 'wpl_location', 'value' => serialize(array(3 => 'Europe')), 'compare' => 'LIKE' ),
I believe the second method would require me to have a (near) identical serialized array as the database, which would not work in the long-term for the system that I am creating, because it will need to match one out of many items in the array.
My updated question:
Should I continue down this path and use the first method, or do I need to dump Option Tree and figure out a way to add the meta-data to the posts in unserialized form so that it can be queried?