create a variable to hold the $current_year
you’re outputting, and check it against each event’s year, resetting the value when you encounter an event with a different year:
$current_year="";
while ( $loop->have_posts() ) : $loop->the_post();
// this is just a simple example of the logic,
// you'll need to extract the year from your date key
$this_year = get_post_meta( $post->ID, 'event_date', true );
if( $this_year != $current_year ) :
// new year, output the year header
// and reset current year to this new value
echo '<h3>' . $this_year . '</h3>';
$current_year = $this_year;
endif;
echo 'event' . $this_year;
endwhile;
Related Posts:
- Custom Post Type Archives by Year & Month?
- Get custom post type slug for an archive page
- Meta_Query as a way how to setup CPT permalinks – is it a good thing?
- Proper way of making custom post type landing page or archive page
- Custom Post Type Archives by Date with Custom Permalink
- Change title in head on Archive page
- Custom Post Type Archives with 0 Posts Redirects as 404
- Page is defaulting to archive page and not designated template
- Better to use a post type archive, page template, or shortcode for generating a highly configurable CPT archive?
- paginate function in archive for custom-post-type
- Alphabetical sorting of custom post type – one letter per page
- Custom post type archive sorted and grouped by date in post meta field
- How to create archive page for taxonomy terms within custom post type
- WordPress custom post type archive with description
- How to list custom post types?
- Custom post type archive page pagination
- Editable content on a Custom Archive page
- Second Custom Post Type Archive
- is_main_query() not working for WP REST API
- CPT Archive with core Category
- Changing number of posts per page on CPT-archive.php, have tried 20-30 code chunks so far
- get the custom post type title/name
- URL of a custom post type’s post format archive?
- Create template for taxonomy results limited by Custom Post Type
- Custom post type archive page blank
- How to display custom post in archive section of the wordpress page?
- What’s the name of the custom post type yearly archive template?
- How can I use archive-{post_type}.php theme template?
- Return the name of the post type
- Use the custom post type archive for taxonomies?
- Archive page for custom post type and custom taxonomy
- How to have multiple archive pages?
- Create a Custom Path to Archive
- Custom Post Type Date Based Archive URL rewrite [duplicate]
- WordPress sitemap with Custom Post Types
- Is possible register two archive pages for single custom post type?
- Custom Post type page content (archive page)
- Group custom post type posts by month
- Creating an archive page or simple template to list all values of a custom field of specific post type listing
- Do not show child pages within a file page
- Tell wordpress to show a single page instead of an archive page
- Custom Post Type archive page listing a 404 or single post
- Want to display my custom date archive to date.php but dont know how
- Rewriting archive page slug to be different than custom post type slug
- Site loads very slow for archive custom post type page
- Stop Custom post type from being searched via URL
- Custom post type category page not working
- paging is not working properly on news archives page [duplicate]
- How can I set up the URL for a category archive for a custom post type?
- Taxonomy Query of Custom Post Displays Archive Instead of Posts
- Pagination not working for archive
- How to have a dynamic slug and rendering the archive-{post_type}.php?
- Remove plugin’s custom post type archive page and single pages [closed]
- WordPress CPT archive page display sticky post first and then display the rest of the posts in same Query
- Permalink Structure for Multiple Post Type Archives by Taxonomy
- Setting up custom post type archives in WP3.1? Any luck?
- Custom Post Type, WP_Query and ‘orderby’
- Display all custom post types in archives.php
- Custom Post Type Archives by Date (stored as meta value) WP3.1
- Hide child term posts on parent term pages
- Compare 3 custom fields and sort by oldest
- How to let custom post type posts show in standard post archive (like in homepage)?
- List all posts in Custom Post Type but group dynamically by Custom Taxonomies
- sort events based on event date custom field
- Custom Post Types and archives
- query_posts with a custom post type, a meta_query and sorting by post date?
- sort order for a custom post-type [closed]
- Loop that displays the first post of every available custom post type?
- How to get “custom post type”-archive with working permalink to it?
- Specify a Page as the parent to the CPT Archive
- Custom template page with custom archives listing by user
- Root slug of taxonomy returning 404
- Unable to get post archive link
- Custom Post Type archive loop separated by term, in specific term order
- Show only posts from one category on custom post type archive page
- How should I structure my post types?
- Display custom post type category, while in a CPT category, then the posts beneath
- Sort entries by date mixing two post types
- Order a custom post type admin screen by a second custom post type title
- Custom post type posts don’t show in archive widget
- Archive for a Taxonomy of a Custom Post type
- Custom post type, global categories — what’s the template name?
- Url to archive page for custom post type
- archive as a page, so that it can be added in the wp_menu_nav
- Sort custom post type by most current date picker
- adding custom post type “name” to single template
- Custom Post Type Archive template not being called
- Dynamic category name in query post
- Archive Template being used instead of Category Template for Custom Post Type
- Displaying custom taxonomy menu in custom post type archive
- Custom Post Type Archive Page showing as 404
- How to sort by multiple values in a nested WP_Query
- Static Front Page not working for custom theme
- Only show categories that have posts within custom post type
- Custom nav menu current item custom link problem
- archive-{custom_post_type}.php not getting recognized wordpress
- How do I sort post listing by child post count?
- title tag for custom post type remove taxonomy name from title tag
- Display results from two Custom Post Types in page template
- Custom order of CPT posts by title, in wp-admin area by default