Im using post meta to store some value. Im having the following in wp_postmeta table:





I need to return posts which have meta_value of 2.

My query:

$args = array(
               'post_type' => 'post',
               'meta_key' => 'mykey',
               'orderby' => 'meta_value_num',
               'order' => 'ASC',
               'meta_query' => array(
                       'key' => 'mykey',
                       'value' => '2',
                       'compare' => 'IN',
$the_query = new WP_Query($args);

But no posts returned... Where i made mistake?


That's not json. You can't put a semi-colon inside a javaScript Object like that.

That's serialized-data. If you return that string & then call unserialize on it & then var_dump you can see what's inside.

Also, see fuxia♦'s Answer Here for more info.

& to Maikal's credit, you can use a meta_query in this situation, but you have to use the correct syntax...

I believe, it's:

'compare' => 'LIKE', 
'value' => '"2"'

& Darren Felton's Answer Here seems to verify that

| improve this answer | |

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.