WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I cannot get this simple meta query to work and I have no idea why.

I have a custom post type registered, called 'ef_project'. I have a few test posts created using post type, each with a postmeta field called 'project_status' - the values can be 'draft', 'inactive', 'expired' and I have created a few posts with each value.

The query DOES return the 'ef_project' posts I created, but does not filter the list down to posts with a project_status meta field of 'draft' - instead it displays any ef_project post regardless of its 'project_status' meta field value. What am I doing wrong here?

// The Query
$the_query = new WP_Query(
    'post_type' => 'ef_project', 
    'meta_query' =>
                'key' => 'project_status',
                'value' => 'draft',
                'type' => 'string',
                'compare' => '='

// Test Loop
if ( $the_query->have_posts() ) {
    while ( $the_query->have_posts() ) {
        echo '<li>' . get_the_title() . ' -  Status: ' . get_post_meta(get_the_ID(), 'project_status', true) .  '</li>';
share|improve this question

It seems the 'type' => 'string' is not right

From the codex

type (string) - Custom field type. Possible values are 'NUMERIC', 'BINARY', 'CHAR', 'DATE', 'DATETIME', 'DECIMAL', 'SIGNED', 'TIME', 'UNSIGNED'. Default value is 'CHAR'.

try and remove the above line from the code and check or try using the below instead.

'type' => 'CHAR'
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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