$last_month = null;
$args = array(
'post_type' => 'post',
'orderby' => 'meta_value',
'order' => 'DESC',
'post_status' => 'publish'
);
$the_query = new WP_Query($args);
while ( $the_query->have_posts() ) :
$the_query->the_post();
$the_month = get_the_time( 'Ym' ); // e.g. 201611
if ( $last_month !== $the_month ) {
if ( $last_month !== null ) {
// Close previously opened <div class="row" />
echo '</div>';
}
echo '<br/><div class="row '.get_the_time("Y").'" >';
echo 'MOnth: '.get_the_time('m');
}
$last_month = $the_month;
?>
<div class="col-3">
<?php the_title(); ?>
</div>
<?php
if ( $the_query->current_post + 1 === $the_query->post_count ) {
// Last item, always close the div
echo '</div>';
}
endwhile;
Related Posts:
- Sort posts on custom field AND after that sort on date?
- Sorting Posts by custom field
- WP_Query: Group events by year, sorted DESC; then by date for each year group, sorted ASC
- WordPress Comments sort by custom meta key
- Understanding the orderby in WP_Query?
- How to list custom fields as headers and list all pages sharing that custom field under it?
- How to order posts on each different category?
- How to use a dropdown to filter posts by custom field
- How to show list of posts with custom field value (a date) that are coming soon
- Comparing Meta Field date in WPQuery using Meta_Query?
- WP Query for all events prior to current date
- Problem with my loops
- Order 2 meta_queries differently in WP_Query?
- Wrap group of wp query posts to parent div by date/year
- Sorting posts by meta values: 2 different orders
- query_posts with sorting on a custom datestamp
- WP_Query – order with usort by custom meta
- Sort CPT by taxonomy AND THEN by custom field
- WP_Query sort by ACF date field (newest first) with blank dates first
- Nested meta_query with multiple relation keys
- Ignoring initial articles (like ‘a’, ‘an’ or ‘the’) when sorting queries?
- Sorting: custom query with orderby meta_value_num THEN by title
- Sorting posts by custom date fields (non standard date format)
- How can I save an array from a random post sequence for later use?
- Limit search results to exact match
- Query two post types and order by two different date fields
- Sorting meta_value as integer doesn’t work
- Get number of comments after modifying comment query
- Sort in WP_Query(), not filter? Is it possible?
- Front End Sorting Questions
- How to sort posts in admin by titles with dd.mm.yyyy format?
- How can i make WP_Query return post image and categories?
- Date query not inclusive despite parameter being true
- Ordering by meta_value AND date NOT WORKING with wp_query
- How add a custom posttype name using ACF field to a query post array
- $wpdb->insert inserting two rows in database
- Sort by posts that have a featured image?
- Ordering Posts Type A by Custom Fields of related Post Type B
- Create unique page without header.php for json feed
- Search Posts with Custom Fields as query
- Sub-loop / nested loops Best Practices
- Add quicklink to in the Admin posts page where I can query by a meta_key
- How to make Meta Query case sensitive?
- Clean up WordPress code that repeats
- Meta_query with multiple keys and multiple values
- Order by empty custom field
- Cutom wp_query for geolocation search, pagination not working
- Help ordering Post loop by two meta values
- How to sort a custom wordpress query by combination of meta values?
- meta_compare not comparing whole integer
- wp_query to print posts if have X custom field value
- Why is WP_Query not displaying expected data?
- I am having problem sorting custom post type using WP_Query
- Order post type by sum of two custom fields
- WordPress Custom Search Form Displaying Unexpected Results
- Get every post with value in meta key
- Using get_posts to get posts based on a checkbox value with Advanced Custom Fields
- Display all posts in a custom post type, grouped by a custom taxonomy. How to sort the posts alphabetically and the terms by ID?
- Order WP_Query results by meta key value in custom query
- Excluding posts with certain value of meta_key keeping posts without that meta_key
- WP Query and date format
- Comparing 2 Decimal Numbers from custom fields and displaying posts
- Sorting posts by Multiple custom fields in defined order
- Custom wp_query – I’m getting ‘all’ post, not the specific post in the query
- meta_query with array as value with multiple arrays
- How to make a query returning pages from multiple parents
- Prioritising and Ordering Posts By Category Name Using A Custom Loop
- Sort custom post by custom field if none order by latest release
- Order (by ASC) posts with meta_key so posts without values are last
- how to include orderby value that is empty?
- How to sort wordpress posts already selected by WP_QUERY
- How sort products by calculate value? ( custom post meta, price, option)
- Getting posts by custom field value
- Order by value of Custom Field using url string
- ACF Post Object meta-query by title not ID
- Case insensitive ORDERBY in wpquery
- How to mix two orderby-parameters into one ordered result
- From admin edit user page query either the user_nicename or username field value of the user profile being edited or viewed
- Query by meta value (add a dropdown of all values)
- Sorting Posts by Taxonomy thats not within the query’s $args
- Order Posts By Custom Field That is an array of objects
- Query by Category and Custom Field – Shortcode
- Combine WP_Query with array of custom data to single loop without breaking the pagination
- Querying posts with meta key and meta value not returning anything
- WP_Query with Pagination and orderby meta_value_num showing duplicates
- Mathematical operations on custom field values? (updated)
- Compare meta key separation
- WP_Query a custom field value bringing back 0 results
- Year based WP Query
- Query custom post type by date field only working when two posts match the query
- Get posts from similar time as current post
- Query posts filter not working
- Switched from query_posts to wp_query, pagination no longer working
- Divide WP_Query posts by date & post type
- Query Posts by date range with fixed beginning and end
- Issue with sorting by post date and custom post type
- Display all custom meta field values from the database using ACF Repeater
- wordpress sorting using array merge by price in ascending order but price with 0 must be show last
- Taxonomy related query not working
- Sort by multiple columns using get_posts