Checkbox in current node to cause unchecking of same box in any other posts?

I have a CCK type with a particular checkbox which is used to drive what gets published on a front page panel/view featured box. There can only be one thing displayed in that featured box, so it is important when a user publishes something and wants it to be the featured item, any other item that is already set to featured gets 'de-featured', but not deleted or unpublished because that node will still get displayed in other areas.

I've created the first half of a rule ('upon publishing' condition) checking if this is that particular node type and that checkbox is checked...

However I'm stuck on creating the second half of the rule (action) to search through all other published of that same custom type, if any of those have the checkbox checked then please uncheck it in those. Essentially an update to set the field to '0' where equals 1, then the current node gets published with its checkbox set to 1 and life is perfect.

Unfortunately I cannot find how to direct Rules to look outside of the current node for this field. Does it have to do with the 'save content' vs. 'unchanged content' because that seems like it references the current node.

Fixing this will drive a cool functionality for a charity website. Thanks in advance!

Groups:
Login to post comments

Nodequeue

liberatr's picture
liberatr - Fri, 2009-06-26 23:21

You don't need rules, you should use the nodequeue module, and tell it to enforce a queue length of 1.

http://drupal.org/project/nodequeue

Ryan Price
DrupalEasy


Solution using rules and PHP snippet

kirkhings - Thu, 2009-07-02 14:51

We didn't want to use yet another module, and to rebuild the other parts to this system. There were other moving parts that I did not describe. We found the solution using Rules.

My rule had the two conditions I described. A coworker added the action "Populate saved contents field" with the following php code:

db_query("UPDATE machine_readable_custom_content_type SET field_custom_target_value= %d", 0); return array(0 => array(\'value\' =>1));

Badabingbadaboom now it works as described. Hope this helps others.