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(
array(
'post_type' => 'ef_project',
'meta_query' =>
array(
array(
'key' => 'project_status',
'value' => 'draft',
'type' => 'string',
'compare' => '='
)
),
)
);
// Test Loop
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
$the_query->the_post();
echo '<li>' . get_the_title() . ' - Status: ' . get_post_meta(get_the_ID(), 'project_status', true) . '</li>';
}
}