Site icon Hip-Hop Website Design and Development

How to only display posts whose meta_value field is not empty?

Three people have already tried to solve this, and we’re coming up nil. I want to show only posts that have a value in the meta_key ‘featured_image’.

So… if ‘featured_image’ is not empty, show the post. Here’s the code:

      <ul>
      <?php
      $args = array(
        'showposts' => 5,
        'meta_query' => array(
          array(
            'key' => 'featured_image',
            'value' => '',
            'compare' => '!='
            )
          )
      );
      $ft_pagination = new WP_Query( $args );
      ?>
      <?php while ($ft_pagination->have_posts()) : $ft_pagination->the_post(); ?>
        <?php $ftimage = get_post_meta(get_the_id(), 'featured_image', TRUE); ?>
        <li>
          <article>
            <a href="">
            <?php if ($ftimage): ?>
              <img src="<?php bloginfo('template_directory'); ?>/timthumb.php?src=<?php echo $ftimage; ?>&w=84&h=60" alt="" />
            <?php else: ?>
              <img src="<?php bloginfo('template_directory'); ?>/timthumb.php?src=/wp-content/themes/ssv/images/review-default.gif&w=84&h=60" alt="" />
            <?php endif; ?>
            </a>
          </article>
        </li>
      <?php
      endwhile;

      wp_reset_query();
      ?>
      </ul>

We have tried literally every combination we can think of, the deprecated meta_* options, query_posts, get_posts, instead of WP_Query… Nothing. Printed the select statement, no meta value field is showing. It exists – for the posts (for every post) and it exists in the db.

We’ve seen every post out there on the topic right now, including these:

query_posts and only show results if a custom field is not empty

http://scribu.net/wordpress/advanced-metadata-queries.html

Zilch. Please help…