4

How could I automatically unpublish a node after Y hours (e.g. after 24h after it appears on-line) but only when it has a specific category - category is based of course on taxonomy's vocabulary.

Important is that an editor has no influence on number of hours after which the node is unpublished - so it must be predefined by the admin.

0

2 Answers 2

3

Use the Rules module for this, by performing these steps:

  • Create a Rules Component to unpublish a node, which is like a getting started with Rules Components.

  • Create a Rule like so:

    • Rules Event: After saving a new node.
    • Rules Conditions: check if "it has a specific category - category is based of course on taxonomy's vocabulary" (as in your question).
    • Rules Action: schedule the execution of the Rules Component, to be executed after 24 hours. You'll have such Rules Action available if you enabled the rules scheduler (sub-module of Rules). This will actually execute the Rules Component "next time cron runs". So make sure to take that into account also to set the frequency of your cron jobs, and/or schedule the Rules Component a bit before the 24 hours have passed (whatever fits for your case). Note that the one who can edit the rule will be able to "predefine" when the Rules Component will be executed.
2

One of the option is, use the Scheduler module.

Scheduler gives content editors the ability to schedule nodes to be published and unpublished at specified dates and times in the future.

Dates can be entered either as plain text or with calendar popups. To use calendar popups in Drupal 7 you need to install the Date Popup module, which is part of the Date module. In Drupal 8 this is built into Core.

2
  • 1
    but only when it has a specific category will this work?
    – No Sssweat
    Jul 11, 2016 at 6:44
  • 1
    The case is that a user (editor) should not have a possibility to maintain that variable - It should be specified by the admin otherwise it will be a mess. A node with category "A" should live for 24h and that's it.
    – nykon
    Jul 11, 2016 at 6:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.