Okay. Simple question. I am creating a content type that has the five star CCK field. The vote is for the node itself not another node.

What would be the correct php code to enter into the Target Node ID? Thanks a ton.

Comments

quicksketch’s picture

return $node->nid
dfrechen’s picture

I have the same problem... and whatever i enter into the target node ID Field it tells me that de default php code returned an incorrect value. I have basically been pasting the code i find here, as i dont know php myself.

value’s picture

this was the only thing that would work for me using pathauto and a couple other modules. Im not sure why the first one doesn't work as I have just recently started working with this module.

It was listed in the Documentation for using Fivestar with CCK fields and Node Comment. It works with or without Node Comment though because the goal is the same either way get the node id of the node being rated.

<?php
if (arg(0) == 'node' && arg(1) == 'add' && is_numeric(arg(3))) {
  return arg(3);
}

if (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == 'edit') {
  $node = node_load(arg(1));
  return $node->field_rating[0]['target'];
}

if (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) != 'edit') {
  return arg(1);
}

drupal_set_message('An error occurred saving your review, no target was specified.', 'error');
return 0;
?>

you also have to be sure to set $field_rating to the name of your field_name of the cck field.

this code covers several cases like adding a new node or editing a node. if there is no appropriate arg specified it errors out.

value’s picture

also make sure your using the most current version of votingapi. a recent patch fixes an issue where the target field was being ignored all together.

dfrechen’s picture

Unfortunatley i still get the php error. Iam using the latest version of both fivestar and votingapi

quicksketch’s picture

This enhancement should make using Fivestar with node reference fields much, much easier. Just select the node reference from a drop-down list: #277045: Make Node Reference Targets Easier.

quicksketch’s picture

Status: Active » Closed (fixed)

The nodereference improvement is included in the 1.12 version of the module. Closing after lack of activity in this issue.