Like Eugene mentioned in his answer you need to run a query for each tag. I would create a foreach loop that went through each tag then queried the latest 2 posts from each.
$tags = get_tags();
foreach ( $tags as $tag ) {
echo '<h3>' .$tag->name. '</h3>';
$tag_query = new WP_Query( array(
'tag_id' => $tag->term_id,
'posts_per_page' => 2,
'no_found_rows' => true,
) );
while ( $tag_query->have_posts() ) : $tag_query->the_post();
// Do stuff
endwhile; wp_reset_postdata();
}
Related Posts:
- Filtering by multiple conditions in the loop
- How to list some posts first in the loop based on post id
- How to get order of posts?
- Order posts by ID in the given order
- Executing Queries in tag.php
- WP Rest API v2 return posts with specific tag
- Loop through all tags & output posts in alphabetical list
- Order posts by tags count?
- How to get any tag ID
- Show all parents and children in custom post type in right order
- WP_Query Order by Specific Post ID First
- How do I run through a WordPress loop called from a filter function?
- Order by title without taking into account ‘the’
- Order by empty custom field
- How to order posts by title after they have already been sorted by category
- WP Query – order posts by meta field first and then order the rest
- How to make posts unqueryable/unpublish posts where ACF relationship field is an unpublished post? [closed]
- Get posts that do not have the same tags as current
- Get posts with no tags?
- relation OR instead of AND – Filtered term ID’s in loop
- WP_Query orderby random do not repeat infinite scroll – one loop
- Why does apply_filters behave different inside and outside a loop?
- Order posts by tags count?
- How to order posts, that have already been filtered by custom taxonomy, by their category names?
- WP_Query doesn’t works inside loop
- Display three sequential posts on each page load, without repeating previous
- Add filter to Orderby Parameter using Array
- Order by multiple meta keys on wordpress
- Can’t seem to get an else statement correct? [closed]
- Get posts that were most recently tagged
- Woocommerce set loop_shop_columns to be 3 in the main shop page loop only and 4 otherwise
- Set Transient on CPT
- Issue in If else condition [closed]
- Create multiple sections for all categories and then queries all the posts for each of those categories
- Pagination not working with WP_QUERY
- Using orderby with 2 meta keys
- Show posts in category
- Both WP_Query and get_posts returning 1 post
- Custom search (wp query by custom fields)
- Order posts by custom column using pre_get_posts
- Iterate through ID’s in loop
- Sorting is not working in WordPress WP_Query
- Add custom WP_Query after the first 3 posts
- Load 3 posts in flexslider slide [closed]
- Loop through multiple custom fields with increasing number
- WP_Query for attachments without duplicating post_parent and displaying tagged image
- Different number of posts showing in development vs production server
- Issue with WP_Query (need a array of selected ID’s)
- Order WP_Query results in order other than ASC or DESC
- How do I display posts with specific value in a custom field into my loop?
- Show sticky post before other WP_Query
- List ALL posts within last week from current category on category page
- Custom query to order by multiple taxonomies
- An archive page without post format (just standard post)
- Filter WP_Query output before it is accessed (pre_get_posts)?
- Custom post type archive organized by category
- Limit the number of posts from a specific category on index.php
- wp_query display posts based on day
- Multiple wp_query loops showing first 5 posts on all pages instead of older posts[Resolved]
- Sorting Posts Based On Meta Value Using AJAX
- Sorting: custom query with orderby meta_value_num THEN by title
- query_posts with sorting on a custom datestamp
- Next / previous posts link doesn’t show up with Posts 2 Posts
- How to exclude posts ordered by comment_count from subsequent wordpress loops using WP_Query?
- Get post closest to today
- Loop the posts between two dates selected using jquery datepicker
- query post based on comparison
- No content found on page 2 of pagination with 1 post per page
- meta_query dates from an array
- Creating array to compare custom field values
- orderby in WP_query doesn’t works
- wp_query pagination links producing 404
- Converting an existing query_posts to WP_Query
- loop through custom post types with meta data
- Posts2Posts, wp_query and orderby issue
- Display First posts without the default featured image
- WP_Query with several meta_query-statements and order by meta_value
- Pull Instagram images into an existing loop?
- Limit Tags display and ad Drop Down Menu
- Loop being strainge
- Using Query In Post Type Archives
- Do not show a custom post if it belongs to a certain custom taxonomy
- Multiple loop for “featured” items returns wrong posts
- $query conflicting with other queries in the same page
- How ‘secure’ are loops?
- Pagination in custom query not working [duplicate]
- Order by meta values
- Query Custom Post Type by Tag
- Multiple loops on index page with sticky post and pagination
- Pagination problem with multiple loops on the same page
- Problem with WP_Query sort
- WordPress Post Looping? [duplicate]
- Change posts archive ordering
- How to do a loop inside a loop?
- Carousel Loop only duplicating
- Remove 5 latest posts from the loop
- Exclude post formats in custom loop
- wp_query->set for several categories
- Get author meta data with no published posts in author.php?
- Query for page content, and query for posts on the same page?