Question

I'm a little confused as to best practise for saving multi-select values in meta fields.

Assuming

<select multiple name="_casestudypost[]">

is my form field

if I store $_POST['_casestudypost'] in a meta_key of the same name? (which returns an array) - how can I find out when 281 is in that array. I've tried:

$args = array(
            'meta_query'=> array(
                array(
                    'key'=>'_casestudypost',
                    'value'=>  281,
                    'compare' => 'IN',
                    'type' => 'NUMERIC'
                )
            ),
            'post_type'=>'case_studies',
            'post_status' => 'publish'
        );

However the generated SQL that Wordpress generates under the hood seems to ask, is meta_value (13,281,45) in 281, rather than is 281 in meta_value (13,281,45).

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top