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?
- When should you use WP_Query vs query_posts() vs get_posts()?
- How to display SQL query that ran in query?
- How can I create a meta_query with an array as meta_field?
- Query multiple meta key values?
- How to Optimize WP site for millions of posts
- Wp get all the sub pages of the parent using wp query
- how to query posts by category and tag?
- Get the ID of the latest post
- How to query for most viewed posts and show top 5
- How to get comments by post ID?
- WP_Query vs get_posts
- Differences between wpdb->get_results() and wpdb->query()
- Is there a way of increasing the speed of this query?
- Get all image from single page using this query
- How can I query all users who registered today?
- Get Terms by IDs with IDs order
- Reversing the order of posts AFTER the query is performed
- what are the numbers between curly brackets in search query
- simple sql query on wp_postmeta very slow
- Using WordPress public query variables
- How to Use Wildcards in $wpdb Queries Using $wpdb->get_results & $wpdb->prepare?
- When/why does ‘$query->get( ‘tax_query’ );’ return empty?
- How to get link and title of next and previous post on single page
- Create pagination and order according to alphabet
- wpdb get posts by taxonomy SQL
- How to List Events by Year and Month Using Advanced Custom Fields?
- Is there any difference between hooks posts_where with posts_join and posts_search performance wise?
- wordpress query – orderby child post date
- How many WordPress SQL Queries per page?
- How to display Section for certain time
- Add multiple value to a query variable in WordPress
- Search custom post type by meta data
- Custom query_var causes displaying posts archive on front page
- Slow wp_enqueue_media()
- Multipart/formatted MySQL query problem
- What is the most efficient way of implementing a favorite post system?
- Query Custom Meta Value with Increment
- Problem with ‘post__not_in’
- Remove [gallery] shortcode altogether
- Is `query_posts` really slower than secondary query?
- Compare two numeric custom fields
- Are there any scenarios where the query_posts may be used?
- wp_dropdown_categories with multiple select
- Advanced Custom Fields – Query Efficiency
- Alter query on edit.php
- Why does get_the_time(‘F j’) return November 30 for all posts?
- Get posts by meta data OR title
- Query by one meta_key and sort by another (possibly NULL value)
- How to tune search argument in WP_Query to show only exactly the same results?
- Perform query with meta_value date
- WP_Query ordered by custom field that is a date string?
- Sort X categories by last update and show image
- Custom query filter not working on woocommerce category page
- How to delete a transient on post/page publish?
- using post__in allow duplicate post id
- Very slow query
- query multiple taxonomy and show post count
- Search Terms – Querying on either description__like OR name__like in the same Term Query?
- Query & Sort Comments by custom comment meta
- Order posts by tags count?
- How to get my loop to pull posts into three columns
- How to display lastest post date in the homepage?
- Using dynamic conditions in ‘posts_where’ filter
- Custom $wpdb Query for Custom Post Type by Category
- How to order posts by modified date without using ‘query_posts’?
- Get a user’s most recent post title
- How to limit search to first letter of title?
- Categories and products in random order
- Counter code for paginated category pages in wordpress
- add_query_arg() XSS Vulnerability
- Count user posts by user ID, Post type and Post status
- Can’t pass table to $wpdb->prepare
- Query set using tax_query with relation ‘OR’ modifies category object?
- $query->query_var[‘post_type’] not set for pages
- WordPress Search Filter Only for Page with Child of Child of Child of Child of Child
- is_archive() doesn’t work on public query var archive pages?
- How to extract all ID variables from a query string?
- When add_query_arg() is necessary?
- Different Main Navigation per category
- How to get category link without a database query