18

Easy! Get the most soonest upcoming pending entry, and use until: {% set firstPending = craft.entries({ section: 'articles', status: 'pending', order: 'postDate asc' }).first %} {% set cacheUntil = firstPending ? firstPending.postDate : now|date_modify('+1 year') %} {% set content %} {% cache until cacheUntil %} ... {% endcache %} {% ...


12

I'm assuming that when you defined your section, you checked the box which says this: Entries in this section have their own URLs ... and then filled out the relevant Entry URL Format and Entry Template values. The great thing about this technique is that it automatically populates the entry variable in your target template. Typically, this is the best ...


9

I haven't tested this, but it should be a good starting point, at the very least. {# Determine the number of days in the month #} {% set daysInMonth = "now"|date("t") %} {# Determine the date range spanning the month #} {% set firstDayOfMonth = "now"|date("Y-m-01") %} {% set firstDayOfNextMonth = "now"|date_modify("first day of next month")|date("Y-m-01") %...


8

You can do this entirely from the order param using MySQL’s CASE syntax: {% set newsItems = craft.entries({ section: 'news', order: '(CASE field_myLightswitchField WHEN 1 THEN elements.dateUpdated ELSE elements.dateCreated END) DESC' }) %} Note that you’ll need to include that “field_” prefix ...


7

You were close, you can set a postDate param on your craft.entries criteria model. And the Twig filter date_modify helps you to get the DateTime from 12 months ago. {% set timeAgo = now|date_modify('5:00 -12 months') %} {% set postDateParam = '< ' ~ timeAgo|date('U') %} {% set entries = craft.entries.section('news').postDate(postDateParam) %}


6

I wouldn’t recommend hacking the MySQL timezone, since that would happen on a global basis, not just for the current user, and will result in some weird race conditions whenever two people are using the site/CP at the same time. Getting an entry to go live at a certain time based on their time zone is a fundamentally different thing than the feature ...


6

You could try this (not tested): {% set month = craft.request.getParam('month') %} {% set year = craft.request.getParam('year') %} {% set firstDayOfMonth = now | date_modify('first day of ' ~ month ~ ' ' ~ year ~ ' 00:00:00') %} {% set lastDayOfMonth = now | date_modify('last day of ' ~ month ~ ' ' ~ year ~ ' 23:59:59') %} {% set entries = craft.entries....


5

You should just be able to do: postDate|date('m') postDate by itself should give you a DateTime object which you can then apply the filter to.


5

I've used this method for sorting by year and month (it could be expanded to support days). On the news/index.html template: {% if month is defined %} {# show an archive of a month #} {% set sortDate = year ~ '-' ~ month %} Entry Date: {{ sortDate }} {% if month != 12 %} {% set nextmonth = month+1 %} {% set nextyear = year %} ...


5

Instead of: {{ entry.postDate.format('d M Y') }} Use: {{ entry.postDate | date('d M Y') }} That should work.


5

There's no build in functionality for this, but you could make a custom plugin that automatically sets the expiration date expiryDate when you first save an entry with a specific entry type. Another option would be to simply filter your entries from your template: {% set entries = craft.entries.type('myEntryType').postDate('>= ' ~ now|date_modify('-10 ...


5

The value you need to set the postDate parameter to is quite complex. If you define a dedicated variable for it, it makes the code more readable and you can more easily debug the value using the dump() function. For the problem itself, you were on the right track. The main problem is a syntax mistake, you are passing in the 'and', '>= ', ... values ...


4

I don't know if it's possible (but would like to see a query solution). There is one problem with your setup: If an entry gets a "substantial update", you can't make a correction afterwards, since it would become the latest item again. I propose you write a plugin which would: Wait for the 'onBeforeSaveEntry' event Check if the Lightswitch-field is "on" ...


4

Ok, found an answer that made it a bit clearer: How do I get elements using getCriteria from a specific date? Basically you can do this: $criteria = craft()->elements->getCriteria(ElementType::Entry); $criteria->postDate = '>'. date('Y-m-d', strtotime("-4 weeks")); $result = $criteria->find(); To get Entries form a month back.


4

$timeslot isn't formatted correctly to be used as the postDate. I'd create a field that takes a date and a time and then use DateTimeHelper::formatTimeForDb() to format for use as postDate. You can't modify the postDate until after the entry has been saved - so will need to resave the entry with the newly set postDate. More info as to why you have to do ...


4

It is possible to work around the Craft 2 bug, by converting the Craft DateTime object to a native one. {% set craftDateTime = entry.postDate %} {% set nativeDateTime = date(craftDateTime|date('c')) %} {{ nativeDateTime|date('n/d/Y g:ia', 'America/Los_Angeles') }}


4

I think the problem is that you are not being specific enough with the date that you are passing to the date function. You are in effect calling date("February") and the PHP date function has to make an assumption and uses the current day of the month, i.e. February 30 which equates to March. If this is correct you will have even more issues tomorrow being ...


3

You can add a hidden field for your postDate to your GuestEntry form, e.g. <input type="hidden" name="postDate" value="{{ now|date("Y-m-j H:i:s") }}" /> This adds the postDate using Craft's YYYY-MM-DD HH:MM:SS format.


3

Looks like maybe you have an Assets field within a Matrix field, which has the dynamic subpath set to: {postDate.year}/{postDate.month}/ But as the error suggests, Matrix blocks don’t have post dates. They have an owner, though, and that owner will have a post date, if it's an entry. So you should use this instead: {owner.postDate.year}/{owner.postDate....


3

Currently, it will ignore them and will only invalidate according to any explicit parameters you've told it to. However, I think it should take into account an entry's post and expiration date so I've added it to our todo list.


3

I think I'd create a twig function or filter to create a custom sort (usort in php), pass the collection to the function so it's returned 'sorted'. Would be interested in seeing if anyone has a nice craft.entries query straight off the bat for this though.


3

I haven't yet used the plugin, but I'd try to import the dates into another, custom datetime field (e.g. myImportDate) to see if it's a problem with postDate being a special field (also goes into other tables in the DB, as far as I know). This would be for testing purposes only... Another hint that might help: Craft usually saves a datetime in a format like ...


3

My SuperSort plugin is built for use cases exactly such as this. It allows you to render each object in your array using a Twig object template and sort the array based on the rendered value. So, you could do something like: {% set sortedEntries = entries | supersort('sortAs', '{{ object.myLightswitch == 'y' ? object.dateUpdated: object.postDate }}') %}


3

It looks as though Craft 3’s built-in duration Twig filter might help: Posted {{ entry.myDateField.diff(now) | duration }} ago. With a bit of additional logic, you can make this more useful, after an Entry leaves a specified window: {% set dateOneYearAgo = now.modify('- 1 year') %} {% set dateOneMonthAgo = now.modify('- 1 month') %} {% set dateOneDayAgo = ...


2

Yes, thanks carlcs! So, as long as your postDate is set to this format "2014-07-31 12:00:00" and NOT your localised version as it appears in the Control Panel, everything works. Thanks to the magic of the import plugin, I can overwrite just the one field.


2

You could use my Auto Expire plugin for this. Just add a new expiration rule with the expiration date set to: { postDate|date_modify('+14 days 5am')|date('c') }


2

Just an update to show final current version of code for calendar - re stefan comment. {% if year is defined and month is defined %} {% set time = (year ~ "-" ~ month ~ "-" ~ "01") %} {% set catslug = craft.app.request.segment(2) %} {% if catslug != 'all' %} {% set category = craft.categories.group('eventFilters').slug(catslug) %}...


2

You could just empty the expiration date and time field and save the entry. Or do you want to do it in a plugin (using PHP)?


2

Found the answer in the database. Apparently Sprout Forms uses the date field named "dateCreated". Also getting it in order by date (newest first) needs 'dateCreated desc' {% for formEntry in craft.sproutForms.entries.formHandle('contact').order('dateCreated desc') %} {{ formEntry.dateCreated|date('d F Y') }} {% endfor %}


2

It looks like you need Craft Pro and even then it's not possible to have the CP in a language that is not installed as a front-end locale. The (new) defaultCpLanguage setting doesn't change this. See Brad's answers here: Change system language + German locale & English CP language resulting in disappeared entries But to help you with your date problem. ...


Only top voted, non community-wiki answers of a minimum length are eligible