:::: MENU ::::

Drupal Published Date equals Effective Date fix

We have a gaming site where the node creation date is irrelevant to the user as they only see it once it is published by our moderators.

Surprisingly, there is no “published on” date in the original Drupal database, so the Views can only sort by the mysterious “created on” date.

As I didn’t want to hammer this problemmette away with the formidable Scheduler module, here’s a quick fix.

Get the Rules module and add this triggered rule:

  • After updating existing content
  • Conditions: updated content type fits, NEGATE “unchanged content is published”, “changed content is published”
  • Custom PHP action:

$node->created = time();
return array(“node” => $node);

Seems to work just fine.

Now I can use the “posted on” date in Views to display the games in a logical manner. Too bad there is no way to do this retroactively.

Here’s my Rules screen shot:

Drupal Published-on Date Rule

And a related article: http://drupal.org/nyobserver.

Reblog this post [with Zemanta]

5 Comments

  • rudders |

    This is very cool but way do I need the “NOT unchanged content is published rule”??

  • Tadej Gregorcic |

    not unchanged actually equals “updated”, and this is a choice because on our site, content gets taken offline and back online and we don’t want it to appear in “new items” if it was unchanged.

  • Kwint |

    To bad the workflow module doesn’t hook into the rules module..

    But I love this workaround. Have a workflow with 8 states setup, with actions that are triggered on a workflow change. Based on the triggered action a rule (yours! :) changes (or doesn’t) the creation time!

    Thanks again for this post, this thing was really bugging me since we do a lot of “timed publish”, “reviewing” and “updating” on our site.

  • liquidcns |

    Ideally i think a module with a custom table for node published timestamp would be a more generic solution (or add it to core). The reason i say this is we have a very similar requirement in that we need to list items based on when they were published; and not have them show at top of lists with a simple typo fix – BUT, we still need to preserve created time as we use it for billing purposes.

  • liquidcms |

    ok, don’t whine if ya ain’t gonna fix it…

    sadly only for Drupal 5 right now; but took a look at this and made a new module called Published which adds a published field (via a table) into the node object.

    admin configurable to let it reset if node goes back to unpublished and then to published again, plus can me manually overriden by user with perm to edit (same as std Authored date field (which is really $node->created).

    i’ll try to get this up on d.org as an official project sometime this week.

So, what do you think ?