How Published On and Publish Date Work

There is enough confusion about these two settings that they deserve their own page. People often think that MODX is not working correctly because they don't understand what these two settings do. This is complicated by the fact that some earlier versions of MODX did not enforce the settings correctly.

Published On

The Published On date (the publishedon field in the database) is actually just a record of when the resource last changed from unpublished to published. The Published On field is set automatically when the resource changes from unpublished to published. This happens when either someone checks the "Published" checkbox and saves it, or the Publish On date is reached and the resource is published automatically.

The only reason Published On is editable is for cases where you want to mislead visitors about when a resource was published or correct an erroneous Published On date caused by accidentally unpublishing, then republishing a resource. Except for those two cases, there's no reason to set or modify the Published On field when creating or editing resources.

If you want to display the date the resource was published, you can do so with something like this:

<p>This document was published on: [[*publishedon]]</p>

Publish Date

This setting (the pub_date field in the database) is for setting a future publication date for unpublished resources. That means that it makes no sense to set both a Published On date and a Publish Date. In fact, the Published On date will be ignored (and cleared) if there is a future Publish Date. There's also no reason to set a Publish Date if you are checking the "Published" checkbox. In that case, the Publish Date will be ignored and cleared (and the Published On field will be set automatically to the current date and time).

Be aware that resources can't be magically published the instant the Publish Date (and time) are reached, because MODX isn't running unless someone visits the site (and I'm not sure if previewing from the Manager or viewing a resource in the Manager counts). The first person to visit the page from the front end of the site after the Publish Date is reached should see the resource as published and it should appear in Wayfinder menus if the Wayfinder tag is uncached:

[[!Wayfinder . . .]]

When that happens, the Published On date will be set to the current date and time and the Publish Date will be cleared. The Published On date will seldom match the Publish Date you set and may be days or weeks later if your site is not visited often.

Unpublish Date

The Unpublish Date (unpub_date in the database) is for setting a future date (and time) that the resource will be unpublished automatically. Like the Publish Date, it won't necessarily happen the instant the setting is reached, but visitors to the site after the date has passed should not see the resource as published. If you want to let people know when a page will be unpublished, you can do so with code like this:

<p>This page will disappear on: [[*unpub_date]]</p>

 

My book, MODX: The Official Guide - Digital Edition is now available here. The paper version of the book is available from Amazon.

If you have the book and would like to download the code, you can find it here.

If you have the book and would like to see the updates and corrections page, you can find it here.

MODX: The Official Guide is 772 pages long and goes far beyond this web site in explaining beginning and advanced MODX techniques. It includes detailed information on:

  • Installing MODX
  • How MODX Works
  • Working with MODX resources and Elements
  • Using Git with MODX
  • Using common MODX add-on components like SPForm, Login, getResources, and FormIt
  • MODX security Permissions
  • Customizing the MODX Manager
  • Using Form Customization
  • Creating Transport Packages
  • MODX and xPDO object methods
  • MODX System Events
  • Using PHP with MODX

Go here for more information about the book.

Thank you for visiting BobsGuides.com

  —  Bob Ray