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`
you’re missing an array within the meta_query element:
(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
There is a better answer at How can I show posts only if meta_value is not empty – Can’t query a null value like this.
Try this code:
Just change ‘NOT LIKE’ by ‘!=’. It worked for me 😉