You can try something like this:
<?php
$tags_array = get_tags();
$news_query = new WP_Query;
foreach ( $tags_array as $tags ) :
$news_query->query( array(
'cat' => $tags->term_id,
'posts_per_page' => 1,
'no_found_rows' => true,
'ignore_sticky_posts' => true,
));
?>
<h2><?php echo esc_html( $tags->name ) ?></h2>
<?php while ( $news_query->have_posts() ) : $news_query->the_post() ?>
<div class="post">
<?php the_title() ?>
<!-- do whatever you else you want that you can do in a normal loop -->
</div>
<?php endwhile ?>
<?php endforeach ?>
Related Posts:
- How to display liked posts of current user in wordpress?
- Get posts by category with pure SQL query
- Change the destination of the URLs in post.php
- get posts by tag to showing in a widget
- Customizing the_tags output?
- WordPress SQL query to tag all posts containing a specific word on title
- How to create an overview of posts with the same tag?
- List WordPress Post and Related Attachments outside of a post page
- Sort query_terms_list for post_tags alphabetically
- Filter products on category AND tag
- Change pure SQL database query to WordPress post query?
- Get posts that match defined arrays of tags
- Query Post interferes with Pagination
- My archives page won’t sort posts by month
- Attachment page tag queries & posts not found
- Not getting input from get_query_var
- Exclude Posts from a Widget
- Show certain number of post from tags
- SQL Query : how copy all tags of post into their post content in wordpress by sql query
- Can I create my own query in wordpress with traditional methods?
- How can I create a meta_query with an array as meta_field?
- Query multiple meta key values?
- Is there a way of increasing the speed of this query?
- How can I query all users who registered today?
- what are the numbers between curly brackets in search query
- When/why does ‘$query->get( ‘tax_query’ );’ return empty?
- How to get link and title of next and previous post on single page
- Search custom post type by meta data
- Multipart/formatted MySQL query problem
- Problem with ‘post__not_in’
- Remove [gallery] shortcode altogether
- query multiple taxonomy and show post count
- Categories and products in random order
- How to Loop within a Loop (Display Children and then Grandchildren)
- How to mass delete one line from all posts after site hack
- Query posts by content lenght
- $wpdb doesn’t appear to work on page inside of a plugin
- Query all posts which do not have tags assigned to them
- Improving WP_Query for performance when random posts are ordered
- Tricky WP Query
- How to export current year posts from WordPress?
- A loop with all articles with certain text strings in tags
- Search query -> Show all pages except certain template
- Custom Query num_rows returns wrong amount
- Using ajax with paging and a custom sub-query
- How do I see the mysql query generated by get_posts( $args )?
- WordPress Query wp-terms SLOW
- I can’t figure out what’s wrong with this statement. $wpdb->query update
- Different values for get_author_posts_url and get_the_author (posts 2 posts)
- query statement containing variable won’t execute
- Query for first 3 posts to change the look and feel
- Exclude posts by post meta value
- Get posts from category with custom query
- Related post based on content
- Slow Search Queries – How to exclude pages, media, excerpt, authors, private posts?
- How to interfere to default search to make it search in custom fields?
- WP_User_Query with more than two custom meta values
- Declaring a var, placing it in a query and using the output of the query?
- Custom Post type showing up in loop, regular posts are not showing up
- Combining two meta_values within one row with query
- Target a page with query
- List only parent attributes on woocommerce admin atrributes page
- Merge CPT Taxonomy and Post Taxonomy in $query->set
- How do I get specific readable results from this query and array results
- I want to get on those users their meta value are like “AGENT” .. but this query is not working
- Add rewrite rule for archive search
- How to create a filter and add query params to all links
- How to fetch courses in all languages in WordPress?
- Get 2 meta values from meta key column
- WordPress add_query_arg from ajax and make url friendly
- My custom pagination not displaying
- Show 5 posts and than 3 posts offset with pagination
- Wpdb->last_query returns bad query
- Merge two queries and remove duplicate
- WP search exclude last letter from string
- Are there any best practices for creating a Like/Favourite feature in WordPress using custom MySQL tables and without any plugins?
- Query reversed when I use “category__not_in”
- How to reduce the load / no of queries on MySql Database
- $query->set( ‘post_type’, ‘post’ ); not working
- How i make a custom sql query for Woocommerce
- Display result from custom post meta query
- Wpdb empty result only if language is Russian
- Include custom table in query
- How to fix this insert? Don’t work for me!
- Display Upload Author & Get Uploaded Post ID
- Display list of most recent grandchild (third tier) pages
- How can I display a number to represent the order of post?
- Ordering posts alphabetically by meta keys and title
- Update vs Insert logic but the last key is always inserted?
- Sort order in get_posts [closed]
- Query unique author ids with published post of type job
- Wpdb generates too many queries
- Query posts alphabetically within this function
- Conditional Tag Custom Querys?
- query posts only works on the first page
- Custom Query for wp_posts using wp_postmeta
- WP Query outputs three items within a div
- Query filter on custom post by current author in post widget for elementor query id
- Sort Posts Alphabetically Based on Specific Category (Divi)
- Querying Posts from ACF Repeater Subfield Select Value