1

I need to automatically set the expire date of a new entry (only) from a specific section.

I know that it's possible to do this via the frontend twig templates, however I need the user to have the flexibility to change the date from the default that's set if they want to.

So when they create a new entry it'll have an expiration date of today + 3 months, but if they wanted they could change this date to next Wednesday or whatever they wanted.

Thanks for your help

2

Sounds like the work of a plugin! Unfortunately, there is no built in Entry API Event for setting anything when a new entry is created.

You could use entries.onBeforeSaveEntry to set $entry->expiryDate to three months from "now", but this wouldn't show until the user saved and returned to the entry. Use a function like this in your plugin's main class file.

function init()
{
    craft()->on('entries.saveEntry', function(Event $event) {
        $entry = $event->params['entry'];
        $now = strtotime(date('Y-m-d H:i:s'));
        $entry->expiryDate = strtotime("+3 months", $now);
        $save = craft()->entries->saveEntry($entry);
    });
}

Hope this helps!

| improve this answer | |
3

If you haven't solved it yet with a custom solution, have a look at my Auto Expire plugin. You would add a new expiration rule with the expiration date set to:

{ 'now'|date_modify('+3 month 5am')|date('c') }

or

{ postDate|date_modify('+3 month 5am')|date('c') }

and make sure the option to allow user changes is checked.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.