1

I'm using a custom field query (or trying to) :

$args =  array(
    'post_type'     => 'pf_cookbook', 
    'meta_query'    => array(
        'key'           => 'pf_cookbook_recipes',
        'value'         => '5',
        'compare'       => 'NOT IN',
        'type'          => 'NUMERIC'
    ) 
);

However, the meta value to be compared is an array. The idea here is I am querying the DB to get the cookbooks which don't contain a certain recipe. The Recipes & Cookbooks are Custom Post Types. The Cookbooks have a meta key 'pf_cookbook_recipes' which I am storing an array of recipe IDs.

Maybe I am missing something?

4

meta_query needs to be an array of arrays - have a look at the code sample in the Codex again.

So, for your example:

$args =  array(
   'post_type'   => 'pf_cookbook', 
   'meta_query'  => array(
                       array(
                        'key'           => 'pf_cookbook_recipes',
                        'value'         => '5',
                        'compare'       => 'NOT IN',
                        'type'          => 'NUMERIC'
                        )
                    )
); 

);

  • Thanks, my brain has gone to mush after 4 days off. Thanks, i'll mark as answered when I can. – Cristian Apr 26 '11 at 10:59

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.