I have array in post_meta like this:
array( 'option1' => 'true', 'option2' => 'true', 'option3' => 'false', option4' => 'true', 'option5' => 'false' )
and I would like to filter
option1 with value true. Can someone help me?
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It only takes a minute to sign up.Sign up to join this community
No, you can't do that via a query. You can request everything then manually filter out items via PHP, but that would be slow.
Instead, you need to address the root problem, that you're storing serialised PHP data in a single field, rather than multiple fields, e.g. you should have an
option1 meta key/value and an
option2 meta key value pair etc
As a sidenote, if you're wanting to use these to filter, perhaps you should be using a taxonomy instead of post meta
I think you can do it with the meta_compare option:
$args = array( 'meta_key' => 'option1', 'meta_value' => true, 'meta_compare' => 'LIKE' );