Reputation: 1490
On a startpage I'm working on, I want to show only the 3 latest posts witch has the tag featured. Must be a really basic thing to do with "The Loop", but I can't find the answer anywhere, and it feels like I have really looked everywhere :(
Can someone help me?
Upvotes: 0
Views: 1581
Reputation: 3240
query_posts('tag=featured&posts_per_page=3&order=DESC'); // show latest 3 posts on featured tag
//query_posts('category_name=featured&tag=featured&posts_per_page=3&order=DESC'); // show latest 3 posts on featured tag and featured categorey
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<!-- do stuff ... -->
<?php endwhile; ?>
<?php endif; ?>
Upvotes: 1
Reputation: 101
You should look to the WP reference https://codex.wordpress.org/Class_Reference/WP_Query It will be like this:
$featured_posts = new WP_Query(array(
'tag' => 'featured',
'posts_per_page' => 3,
));
Upvotes: 3
Reputation: 928
Use following query to get latest 3 post.
"SELECT * FROM tablename WHERE featured=1 ORDER BY id DESC LIMIT 3"
*id=pk
Upvotes: -1