Query not retreiving custom field post
-
Hi,
I have a query that is set up to display a featured post, to be retrieved by way of a custom field associated with the particular post. From what I have I can’t see anything wrong and I’ve been looking at it all too long now to perhaps notice something I may have overlooked? The query looks like this:
<?php $featured = new WP_Query(); $featured -> query('showposts=1'); while($featured -> have_posts()) : $featured -> the_post(); $wp_query->in_the_loop = true; $featured_ID = $post->ID; ?> <?php if (get_post_meta($post->ID, 'preview', true)) { ?> <div class="image_block"> <img src="<?php echo get_post_meta($post->ID, 'preview', true); ?>" width="230" height="160" alt="<?php the_title(); ?>" title="<?php the_title(); ?>" /> </div> <?php } ?> <div class="text_block"> <h2><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2> <small>posted <?php the_time('jS M Y'); ?> in <?php the_category(', '); ?> tagged <?php the_tags(''); ?></small> <?php the_content('Read On?'); ?> </div> <?php endwhile; ?>
With a custom field ‘preview’ associated with only the one post I wish to feature, the value of which is a url for the image to be used with the content of the featured post, should this not work?
If I put an else statement in to display the string ‘No posts match your criteria’ the query returns this string, rather than the post. If I do not put in the else statement the query returns the latest post, but still NOT the post with the custom field.
Is there something I’m doing obviously wrong?
Thanks.
- The topic ‘Query not retreiving custom field post’ is closed to new replies.