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?
- How to display categories of my Custom Post Type?
- Filter next_post_link() and previous_post_link() by meta_key?
- Drag n Drop Post Order for multiple Custom Post Types
- how to sort post in admin column by recently
- Make permalinks based on an ACF-field
- How to get a list of term names of the custom post type im currently on in single.php
- is_singular won’t call my functions?
- How to Sort Custom Field Admin Column by Date
- Sort Posts Best Practice
- Custom Post Type sorted by Title
- How do you output custom code between posts in the loop?
- wp_update_post based function works on existing posts, but not new posts
- How to Display ACF Relationship Custom Field as Link to Specific Custom Post?
- Output custom post shortcode. Help spot the error.
- Blog page showing same content as homepage
- How to rank custom post type from score points
- Custom post type permalink returns bad url
- get the custom post type title/name
- Push metadata in array
- Get custom post type list for every category shortcode
- Default sort on admin columns with meta date hides draft posts with empty date value
- How do i calculate the total of values of custom fields in custom post types?
- Custom post type – get_day_link()
- Custom Taxonomy terms aren’t getting referenced or saved in Quick Edit or Bulk Edit, only on Single product page?
- Use custom metabox to update automatically a post after a given date
- get_post_meta not working on publishing
- Troubles with acf/save_post and WP_Query
- Query custom post type with ACF Date
- CPT archive admin menu label
- Order Custom Post Type by Custom Field Value
- Adavnced custom fields relationship query plus query inside
- Different Category system needed for the Custom Post Type
- Specifying Mouseover Icon for Custom Post
- Removing full title and breadcrumb header container for a specific post type
- Using Pagination for Custom Post Type and keeps returning 404
- Validate Custom Post Type fields
- CPT Repeatable Fields + Undefined Index
- foreach loop inside the loop creating duplicates in output
- Custom loop request based on custom field
- Custom Post Type Causes Error: Warning: call_user_func_array()
- redirect after submiting post for review
- Get only parent post in archive post
- update custom taxonomy custom fields
- Filter taxonomy by CPT
- Sort custom post column by generated value?
- Filter posts by their related field’s custom field
- If ACF Post Object post has custom taxonomy term…
- Changing default admin column sorting to an ACF Date Picker field
- Tell wordpress to show a single page instead of an archive page
- Wrapping an unknown amount of posts inside separate HTML Containers during WP_Query loop
- Some permalinks on Apache/localhost development setup return 404’s when set to anything other than plain permalinks
- sorting in wp query based on custom field value
- PHP Notice: Unidentified index
- Include images from pages in wp search.php results in default wp search
- WordPress loop add heading before first of type
- How to make a shortcode for my WP_Query Loop? [duplicate]
- Pods pagination erases my sub menu
- Why is my custom post type slider only displaying the latest slide?