1

I am formulating a query to pull from a custom post type, with values matching a custom field. The results are blank although I have 3 values set matching the custom field.

Is my query formulated properly?

enter image description here

My query is:

$turtleposts = array('post_type' => 'turtle', 
                                       'posts_per_page' => -1,
                                       'meta_query' => array(
                                            array(
                                              'key' => 'derby',
                                              'value' => 'Yes',
                                              'compare' => '='
                                            ),                                                
                                        ),
                                       'orderby' => 'meta_value',
                                       'meta_key' => 'name',
                                       'order' => 'ASC');
  • The value of your field isn’t “Yes” so your query is not returning any posts. The value you show is a serialised array. If you change your meta field to a plain text field with the value “Yes” then the query may work. – Andy Macaulay-Brook Mar 15 at 18:55
  • The value of the field is "Yes" and I understand that is in a serialized array. I'll post an updated answer. The correct way to do this is to use "LIKE" in the compare. – plumwd Mar 15 at 18:57
  • But then your query will also match “Yesterday” – Andy Macaulay-Brook Mar 15 at 19:00
  • Ah yes I see that. I need to use a checkbox. – plumwd Mar 15 at 19:02

Your Answer

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

Browse other questions tagged or ask your own question.