Getting post id in WP_Query
I am trying to execute the query in WordPress to retrieve the last post from featured category, then check for its custom field and show an image stored in it. Well, my code is not working for some reason.Can you spot any error there? Or point me in the right direction?
<?php $featured = new WP_Query('show开发者_如何学Cposts=1&category_name=featured'); ?>
<?php if($featured->have_posts()) : ?>
<?php while($featured->have_posts()) : $featured->the_post(); ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
<img src="<?php echo get_post_meta($post->ID, 'image3', true); ?>"></a>
<?php endwhile; ?>
<?php endif; ?>
Many thanks!
I hope this will do what you expecting
$args['category_name']='featured'; // posts from particular category
$args['orderby']='date'; //to get latest post
$args['order']='DESC';
$args['numberposts']='1';// to get only one post from post list
$featured = new WP_Query($args);
精彩评论