Thanks. I've been knocking this around, and I can't get it to display anything where the text should be.
The custom field is not empty, because the evaluation is successful.
Yet when I use get_post_meta to retrieve the field contents and try to echo it to the browser, it's outputting nothing.
If I change 'true' to 'false' above, it echoes 'Array' - which suggests to me it isn't finding any data. But I can't see how that's possible if it's passed the evaluation.
Here's my code in full:
<?php
$args=array(
'meta_key'=>'custom-field-key',
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 10,
'caller_get_posts'=> 1
);
$customflag = null;
$customflag = new WP_Query($args);
if( $customflag->have_posts() )
{
echo '<li id="recent-custom-posts" class="widget widget_recent_entries"><h2 class="widgettitle">Recent Posts</h2> <ul>' ;
while ($customflag->have_posts()) : $customflag->the_post(); ?>
<li><?php the_author(); ?>:
<a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>">
<?php
$customflagtext = get_post_meta($post->ID, "custom-field-key", false);
if($customflagtext !== '') {
echo $customflagtext;
} ?>
</a></li>
<?php
endwhile;
echo '</ul></li>' ;
}
wp_reset_query(); // Restore global post data stomped by the_post().
?>
This outputs a list of ten posts, each in the format 'Author: Array' (where Array is linked to the correct post).
If I put 'false' back to 'true' to retrieve (supposedly) a single string, I get nothing.
What am I missing? How can a field be not-empty and empty all at the same time?