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
- Some doubts about how the main query and the custom query works in this custom theme?
- Using a custom WP_Query with get_template_part loop
- WP_Query orderby post__in remains ineffective in the Loop [closed]
- Loop within a loop?
- ajax category filter
- Display posts the match taxonomy term linked from wp_list_categoies?
- Pagination with 5 posts per page
- Reverse chronology of post listing
- How to support multiple search terms query within one process?
- Order posts by date and then by custom field
- Order by the results of a function with WP_query
- How to order posts in wp_query by a meta_value of the corresponding author
- Splitting the main query in multiple loops with query_posts and/or pre_get_posts?
- Order WP Query posts by custom order calculated from post meta values
- WP_Query to get posts in a specific category and post format
- Refine/Filter WP_Query Posts with jQuery or Ajax
- Can’t get drafts with WP_Query using post_status parameter
- Wp query orderby ‘title’ doesn’t work
- How can I order Wp_Query hierarchically?
- Prevent duplicate post from dynamic multiple loops
- When to add_filter() to Custom Query
- if/else on custom query gives 200 OK when condition not met?
- Order by custom table and multiplication
- Multiple Loops Inside a Function
- Storing query variable and then using wp_reset_query
- Display post from current category and same tag?
- Complex WP_Query order request: DESC by day, but then ASC by time
- Can I set my WP_Query to be a Main Query?
- How can I make WP_Query get posts that have a tag but also have random other tags?
- Change query based on post type while staying in loop
- Sort wordpress custom posts based on meta value
- Get a list of posts with associated meta_value
- $WP_Query: How to display excerpt on first post only
- How to make search for posts using get method?
- How to get list of posts from permalinks?
- get_template_part causes 500 error
- How to Order a list of taxonomies? orderby?
- WP_Query – Adding “offset” posts to the end of the loop
- Conditional operator OR not working with custom fields
- wp_query is showing posts from other categories
- Should I reset $wp_query?
- Exclude a Woocommerce product from WP_Query
- WP_QUERY wrong ammount of posts
- Expecting statement error from php loop using ACF plugin
- How do I sort this custom list of sticky posts
- Query only displays one page_id
- Randomly select one of last 3 posts
- I am officially missing something about transient posts
- How do I get the content of a custom instance of WP_Query?
- how to retrieve WP_Query without ordering by date [duplicate]
- WP_Query orderby
- Only show tag with the same id as the post
- How to sort store location by specific category order in WP store locations
- How can I have sticky posts while ALSO showing posts from a specific category using one WP_Query?
- ACF: How can I publish values of ACF fields in a loop while using wp_query?
- Order posts alphabetically with numbers but some of the posts has numbers in the title
- WP_Query random ordering not working since 5.4
- Show a message if there are no active posts in category
- SEARCH QUERIES – REVERSE OUTPUT
- Problem with my loops
- Paging works correctly on local version, but not live?
- Custom post type loop error: Trying to get property of non-object
- How to add in WP_Query to every 3 posts displayed? [duplicate]
- How to make a wordpress loop file that displays posts based on certain conditions
- Custom loop – Isolating post meta output depending on current query taxonomy terms
- How do I display posts with specific value in a custom field into my loop?
- wp_query pagination links producing 404
- Pagination problem with multiple loops on the same page
- Output ACF field dynamicaly within a taxonomy loop [closed]