Drupal – Rules – Unpublish a Node After a Given Period X Days

November 9, 2011 / CMS

Here is a small howto that will show you how to unpublish a node after a given time can be in days, in seconds, Drupal uses the module Rules

First, what does the module Rules?

Rules can be viewed as an evolution of the core module and the trigger is the enhanced version of Drupal 6 work flowing to Drupal 5.

Rules allow you to discover events, and perform actions (post a comment, send an email …) automatically with the possibility of moving conditions.

Here is a small how-to to un-publish content after a certain time, it could be 15 days, 30 seconds, Wednesday, Nov 09 …

First, you must install the Rules.

Creating Rule Sets: Go to / admin/rules / rule_sets

  • Click on “Add a new rule set”.
  • Add a title, eg “Unpublish content {} rule set” with the name and machine-readable “unpublish_content.”
  • In the Arguments, select “Content” as the data type, enter “Content {argument}” as a title, and “unpublish_content_content” as the machine-readable name.
  • Then save your form.
  • You will be redirected to the overview of the rule sets and you can see the rule set that you just created.
  • Then click on it and add a new rule by clicking the “Add new rule”
  • Add a title such as “Unpublish {action} rule” and click Save.
  • You will then be on a page for editing the rule click on “Add an action.”
  • You will have a selection list, you should choose “Node | Remove the contents of the publication” (NOT “Rule Set | Publish content”!) And confirm by clicking Next.
  • You have nothing to do normally in the form on which you have been directed, except change the title to “Unpublish content {action}” to more easily track and then save.
  • Go to the page admin/rules / rule_sets and click on your rule (rule Unpublish content {set})
  • Then click on the action (action {rule} Unpublish) to edit
  • Add Action and select “Schedule Unpublish content»
  • Choose the identifier [unpublish_content_content: nest] if you follow the terms I used, otherwise fit the machine-readable name given in the above arguments.
  • Set the date of execution, for example, 2011-12-12 10:33:55 or “one day”, you can refer to the PHP formats strtotime ()

Creation of or triggers (trigger): Go to / admin/rules/trigger

  • Click on “Add a New Rule”
  • Choose to label “Unpublish content triggered rule {}”
  • Select “Node | After saving new content” and save
  • Add Action
  • Select “Rule Scheduler | Schedule rule Unpublish content {set}”
  • Add Condition “Node | Content is published ‘
  • You can also add a requirement for a given content type, why add a new condition
  • And select “Node | Content Type as” and choose your or your content types.

Well, your rule is created and will be executed each time when the cron runs. I hope this tutorial has helped you a little.

Looking for fast, reliable, and secure hosting solutions for your expanding website? Check here our web hosting services.

1 Comment

  1. Well, that is my first check out to 115.124.127.118/~devteamgrowth/bod-blog ! We are a group of volunteers and starting a brand new initiative in a regional community in the exact same niche. Your blog supplied us valuable information to work on. You have done a marvelous task!

Leave a Reply

Your email address will not be published. Required fields are marked *