Created
April 15, 2025 08:08
-
-
Save terryupton/cd2c1ffcaff54922e42ac9b53e8400c1 to your computer and use it in GitHub Desktop.
How to cache bust in Craft CMS based on pending posts/dates.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{# Fetch the next **pending** entry due to go live #} | |
{% set nextToCome = craft.entries() | |
.section('articles') | |
.status('pending') | |
.orderBy('postDate asc') | |
.one() %} | |
{# If there is no entry due to go live, cache the fragment for a year (change to what you need) #} | |
{% set cacheExpiry = nextToCome ? nextToCome.postDate : now|date_modify('+1 year') %} | |
{% cache until cacheExpiry %} | |
{# Query in your cache tags #} | |
{% set items = craft.entries | |
.section('articles') | |
.orderBy('postDate asc') | |
.all() | |
%} | |
{# Your loop... #} | |
{% endcache %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment