It’s probably best to loop through your posts two times. Once to group them by year and once to print the posts.
Something like this: (not tested)
$formatted_posts = array();
while ( $subsQuery->have_posts() ) : $subsQuery->the_post();
$year = get_field('year');
// add them to formatted_posts array and group by year
$formatted_posts[$year][] = $post;
endwhile;
foreach($formatted_posts as $year => $posts) {
// print $year
foreach($posts as $post) {
// print $post
}
}
Related Posts:
- using ACF datepicker to filter posts on a page
- How to sort a table of custom posts by column containing custom field
- Meta Query “IN” doesn’t work with ACF checkbox filter
- List events by month
- Show ACF field from custom taxonomy and display on the single template
- Change message given when deleting post from custom post type
- How to make in WordPress admin panel sortable column for the custom field, that count the number of page impressions?
- Link users to a custom post type
- How to display Custom Post Type Post based on Tag with Shortcode Parameter?
- get_posts of Custom Post Type AND Custom Taxonomy
- WP_Query to select custom post type with Advanced Custom Fields (ACF) date
- WP_Query order by custom field, then randomly order some of results
- How to update post meta on uploaded image from a custom form?
- Displaying custom field according to date
- Sort a custom post with ACF: Date Picker & Display Featured!
- Custom Post Type page sorts differently on different environments
- Create short URL with auto 301 redirect
- Query entries from custom post type in an ACF flexible content field
- Creating a “glossary” of WordPress posts of a specific post type
- meta query not retrieving posts
- How can I sort the order of multiple custom field values in a custom post type?
- Fetch data from two custom post types and create multidimensional array for output to html table
- Custom front-end form for adding post – Category problem
- count & sum the value of custom field of the author post in dynamic posts
- Sort custom posts by date and then by taxonomy
- Grouping custom wordpress post types by acf value
- WordPress – display relationship between blog posts and custom posts
- Custom sorting in post columns by ACF Pro Select Field
- Load info from customposttype into template page
- Sort custom post type by custom datepicker instead of filtering
- Custom post type order by post_title
- CPT: execute code after load if parameter is set
- ACF Post Content Not Being Searched
- Display related post content and custom field content
- Grouping and paging CPT events by month with custom field date
- Can’t pick up a field created with Advanced Custom Fields
- Custom post tag images not displaying with ACF
- Get month and day from a Date Picker custom field
- Custom Post-type not returning the right child_of
- Getting ACF relationship field information
- How to I add count of custom posts listed in a post as a prefix to its title
- Is it possible to specify a time interval (from, to) in ACF with date picker, or other custom field?
- Using several custom fields as custom post title
- Custom Post Type without an archive page
- How to retrieve category NAME instead of ID in a function with a taxonomy custom field?
- Get rewrite slug of custom post type in template
- Show Different Header on a Specific Post ID
- “add_post_type_support” with Custom Post Type & ACF
- Get Post Primary Category
- Custom Post type with ACF in REST API, how do I get those values?
- Weird problem happening with custom taxonmy when creating/updating posts
- ACF simple text field value not showing
- A good strategy to print custom posts (offer) that are checked inside the metabox of a post?
- Post Object Filter by Custom Field, not title (ACF)
- Custom Post Types not showing, custom WP_Query
- Admin notice not displaying
- Can’t get order_by meta_value_num to work properly
- Custom post type ‘orderby’ => ‘meta_value’ not working
- Create custom post type on successful woocommerce order [closed]
- Rewrite WordPress URL to show CPT meta field data
- Create 3 Level Relations with ACF and WordPress
- Custom Post type and Custom Field WP_Query
- How to rank custom post type from score points
- Display multiple custom post types and sort them chronological by one of their fields
- Adding custom tables to WordPress
- Advanced custom fields sort repeater by date
- Taxonomy Archive: Display only one post per term from separate custom taxonomy
- Sorting multiple custom post types without a meta key/value pair by sort order
- Very Slow Page – How to Optimize # of Queries?
- Dynamic page outside WordPress
- Using wordpress template tags within an array
- Order By Post Type ThenBy Taxonomy
- Getting the URL of the parent page
- Custom query to filter posts that have current post as a taxonomy [closed]
- Multiple ACF Repeaters within a Custom Post Type
- Combining sorted and random CPT
- How to change post featured image using a custom field of category?
- Custom post type permalink returns bad url
- Return the thumbnail meta data for getter and setter
- How to display selected taxonomies by their parent
- Validate custom fields before save using WordPress Rest API
- Custom Field Order by Last Name and First Name
- Pagination for custom php code
- What’s the difference between same wp functions get_posts(); functions in different form?
- Changing number of posts per page on CPT-archive.php, have tried 20-30 code chunks so far
- How to: Display ACF [fields] on Custom Post Types Utilising WordPress ‘Hooks’? [closed]
- Custom Post Type Loop throws 500 error when used in widget
- how to check if custom post type column already exists?
- Get posts from a custom post type by child categories of a parent category
- Received nothing after executing AJAX post function
- How to make sure content doesn’t display if selection is empty
- Custom Post-Type not in admin menu
- get the custom post type title/name
- Sorting custom post type columns with external data and without meta values
- Page vs Custom Post Types Differences/Issues
- Custom fields vs. Custom post types for a Portfolio Website
- If post has custom field then display css-class
- Push metadata in array
- How to customize a permalink (URL) structure?
- Troubles with saving metabox