I’m trying to show result for a custom field that is not empty on a custom post type but getting no results?
<?php
if (have_posts()) :
$args = array(
'post_type' => 'programmes',
'meta_query' => array(
'key' => 'linktovideocatchup',
'value' => '',
'compare' => 'NOT LIKE'),
//'caller_get_posts' => 1,
);
?>
<?php query_posts( $args ); ?>
<?php while (have_posts()) : the_post(); ?> `enter code here`
3 Answers
you’re missing an array within the meta_query element:
$args = array(
'post_type' => 'programmes',
'meta_query' => array(
array(
'key' => 'linktovideocatchup',
'value' => '',
'compare' => 'NOT LIKE'
)
)
);
(this is required to allow for querying of multiple meta fields.)
you also had an extraneous comma after the meta_query array element which can cause problems.
i think you should also be able to use the operator ‘<>’ rather than ‘NOT LIKE’, i believe it’s more efficient.
there’s a good write-up on the meta_query functionality here: http://scribu.net/wordpress/advanced-metadata-queries.html