I use the Rules module together with Rules Scheduler (a Rules sub-module) to automatically unpublish content at a specified time, as explained in the steps below. These steps use content type = article
, which has an expiry date field which is set by the user. When cron runs, the expiry date field is checked and the content is unpublished.
Step 1: Create a Rules “Component”
Here is the Rules Component to be created (in Rules export format):
1 2 3 4 5 6 7 8 9 |
{ "rules_unpublish_a_node" : { "LABEL" : "Unpublish an Article", "PLUGIN" : "action set", "OWNER" : "rules", "REQUIRES" : [ "rules" ], "USES VARIABLES" : { "node" : { "label" : "node", "type" : "node" } }, "ACTION SET" : [ { "node_unpublish" : { "node" : [ "node" ] } } ] } } |
Step 2: Create a “Rule” using the Rules Component
Here is the Rule to be created, in Rules export format:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
{ "rules_unpublish_article" : { "LABEL" : "Unpublish Article", "PLUGIN" : "reaction rule", "OWNER" : "rules", "REQUIRES" : [ "rules", "rules_scheduler" ], "ON" : { "node_insert" : [], "node_update--article" : { "bundle" : "article" } }, "IF" : [ { "node_is_of_type" : { "node" : [ "node" ], "type" : { "value" : { "article" : "article" } } } } ], "DO" : [ { "schedule" : { "component" : "rules_unpublish_a_node", "date" : [ "node:field-expiry-date" ], "identifier" : "Unpublish Article with node ID [node:nid]", "param_node" : [ "node" ] } } ] } } |
Note that the above rule refers to the Rules Component from the previous step. It’s in Rules export format, just import it in your own environment via copy-paste (after you adapted article
in it to fit the machine name of your content type).