Jump to content

How to fill a field automatically after a page is published?


Michael van Laar
 Share

Recommended Posts

I’m just building my new blog with processwire. Regarding the publish date of an article I’d like to have the same functionality WordPress provides.

My idea:

  • I include the “Publish From Date“ field of the Schedule Pages module in my template.
  • I use the “Publish From Date“ field in my frontend templates to display the publishing date of an article and to sort articles chronologically.
     
  • When writing a new article, I’d like to have two options:
    1. If I want to schedule the publishing of an article, I fill the “Publish From Date“ field with the desired date and time.
    2. If I want to publish a new article instantly, I leave the “Publish From Date“ field empty and simply click the “Publish” button.
      In this case right after publishing – or even better before the publishing workflow step is finished – a page with an empty “Publish From Date“ field, the “Publish From Date“ field should be filled with the current timestamp automatically. Otherwise no publishing date could be displayed in the frontend and the article couldn’t be sorted as latest one correctly.

Is there an easy way to achieve this auto-filling of the “Publish From Date“ field when publishing a page?

I guess I have to hook into anything to achieve that. I have not worked with PW hooks by now, so my knowledge of hooks is very limited. But I couldn’t find anything “publish” related in the PW hooks cheatsheet.

Of course I could simply fill the “Publish From Date“ field manually even if I want to publish the page instantly. But I’d like to use this functionality for other blogs, too – with editors who are used to the publish date field auto-filling like WordPress does it.

Link to comment
Share on other sites

Don't date/time fields have the option to default to the current time/date.

That's how I handle it and then manually set it if required.

Yes, date/time fields have this option. But since the publish_from field is part of the “Schedule Pages” module, this would result in not being able to save a new article without publishing at all.

That’s why I implemented Kongondo’s solution today.

Link to comment
Share on other sites

Maybe how we do it in the Blog Module can be of help. Have a look at the Hooks here.

Works like a charm. I made minimal modifications to make it work without the rest of the Blog Module:

https://github.com/MichaelvanLaar/PW-AutofillPublishFromDate

My version of the module simply does its job for every page which has a publish_from field which is installed with the Schedule Pages module.

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...