I have a product content type and a review content type. A user can create a product node and then several users can review it. There is a node reference field in the review content type that links the product type using the node reference url widget.

The user can create and edit the product node but it is not published. However, there are links from the node reference url widget that allows for reviews to be attached that get published immediately. Now I have views on other pages with reviews that link to an unpublished node. This doesn't work.

How do I allow for reviews to be made but are not published if the product is unpublished and published if the product is published? Are there techniques using Rules?

2 Answers 2


I would look into rules. This should be a simple problem solve with them. If not here is how you would code it in a custom module

Drupal 6:

 *  Implements hook_nodeapi()
function MYMODULE_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  switch ($op) {
    case 'presave':
      //check for correct type
      if ($node->type == 'review') {
        if ($node->field_product_node_reference[0]['value']) {
           $product = node_load($node->field_product_node_reference[0]['value']);
           if ($product->status == 0) {
             //product is unpublished, set review to unpublish
             $node->status = 0;

Drupal 7: hook_nodeapi() has been change. Create MYMODULE_node_presave($node). Use the same code.


Rules Views Bulk Operations is being worked on which will hopefully allow a change in a node trigger, through a Views argument, a VBO reaction that will, for example, unpublish a set of referenced nodes.

However, I just needed to hide Reviews in Views that were spread around the website. This is done by using the Relationships content: reference and adding a filter content: published that uses the referenced node relationship to test if it's published.

The reviews will always remain published. They can be viewed if people know where to look which doesn't make a difference. However, now an anonymous user doesn't land on the front page sees a view with a new review that links to a product which isn't published resulting in a page not found error.

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.