$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
- Get a list of posts with associated meta_value
- Query to get siblings and parent page
- Extend product search with meta in WooCommerce
- how to make members list directory through wordpress post custom meta key.
- Order by empty custom field
- WP_query sorting can’t sort danish letters (æ, ø, å)
- Query posts without meta preload
- Adding multiple meta_key fields as orderby options to a WP Query via a function
- Cutom wp_query for geolocation search, pagination not working
- Large AND OR query timing out
- Help ordering Post loop by two meta values
- meta_value_num not ordering all items
- Include data from custom table in WP_Query
- Categorising search results based on Custom Fields
- Taxonomy and Date in same query?
- How to sort a custom wordpress query by combination of meta values?
- echo a specific meta_key queried through a custom post
- Shortcode for latest -not expired- posts
- date_query seems to be ignored by wp_query
- Gallery shortcode numerical sorting
- Query all posts if multiple meta key don’t exist
- meta_compare not comparing whole integer
- Redirect to another page using contact form 7? [closed]
- Does wp track views for posts?
- Sort WordPress Posts Meta value by Week not Day
- Search posts missing a particular custom field
- Display Current Post’s Position in Custom Taxonomy
- wp_query to print posts if have X custom field value
- wp_query get data from advanced custom field in wordpress
- Why is WP_Query not displaying expected data?
- How to compare a date in custom field with today’s date in custom WP_Query?
- How to order WP_Query to group results?
- WP_Query Meta_key is text value and need to sort as numeric not working
- filter wp_query result with custom field values
- 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
- Query post by date (stored custom field meta as yyyymmdd) and differentiate across 12 months
- Select custom posts by meta_value and sort by a different meta value
- Conditional operator OR not working with custom fields
- Get users based on month ACF datepicker field
- Sort custom post type by most current date picker
- WP ForLoop to compare meta information of posts to determine what post to display
- Filtering posts by archive showing all years
- WP_QUERY with group by with custom fields
- Intiger meta value with ‘>=’ returns posts with lower value
- Display posts with specific value first in query
- get_posts custom field
- Get every post with value in meta key
- Using get_posts to get posts based on a checkbox value with Advanced Custom Fields
- wp_query posts with custom fields number smaller than
- Sorting search results with custom dropdown
- Posts query according to meta box date
- create metabox to activate slider
- Query posts using less than
- Get specific ACF key and value from all posts – no access to DB
- Retrieve select tag custom values from array and display them in current page with wp_query?
- Display custom post type for specific user
- 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
- How do I sort this custom list of sticky posts
- Excluding posts with certain value of meta_key keeping posts without that meta_key
- Query only displays one page_id
- WP Query and date format
- Querying a large number of posts including their custom fields data
- Ordering posts by custom field and grouped by month
- Display post meta conditionally based on it’s value
- Query using string from custom field as array value
- Limit loop to future events
- add_query_arg to compare and display events from a certain date
- Show single posts date, in a page of posts
- Comparing 2 Decimal Numbers from custom fields and displaying posts
- Orderby two meta fields not working
- 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
- Added Date Filter To Popular Posts Query
- How to sort queried pages by an array of page ids?
- Adding pagination to sub-wp_query within a singular post page
- Custom Query Fields – Altering Meta Value
- Magazine style frontpage with multiple categories/loops and no duplicate posts