I`ve created new content type. It has one list field (field_birhtday[key]) with some values and computed field.
I need to associate birthday field values with taxonomy terms of vocabulary 1.

For example:
list field values: years of birthday -1|1980 2|1981 3|1982............1999
I make a choice 1980, save node, this node associate with term: "Generation P"

values from 1980 to 1989 associate with term "Generation P"
1990-1999 - "Generation Next"

Comments

yuku’s picture

can anyboy help me? pls.

Firewolf’s picture

I think it is similar to something I have done.
I start with a CCK date field 'cv_geboortedatum', which is the birth date.

In the next code I calculate the age and store it in a computed field 'cv_leeftijd', which is the age.

$birthday_date = date_make_date($node->field_cv_geboortedatum[0]['value']);
$birthday = $birthday_date->db->parts;
$bdayunix = mktime(0, 0, 0, $birthday['mon'], $birthday['mday'],$birthday['year']);
$nowunix = time();
$unixage = $nowunix - $bdayunix;
$age = floor($unixage/ (365 * 24 * 60 * 60));
$node_field[0]['value'] = $age;

Next I use the age result to check the right category, and assign the category id (tid) the right id. I looked up the tid values first in the category table.

if ($node->field_cv_leeftijd[0]['value'] < 25) {
  $node_field[0]['value'] = 16;
} else if ($node->field_cv_leeftijd[0]['value'] >= 25 && $node->field_cv_leeftijd[0]['value'] < 30) {
  $node_field[0]['value'] = 17;
} else if ($node->field_cv_leeftijd[0]['value'] >= 30 && $node->field_cv_leeftijd[0]['value'] < 40) {
  $node_field[0]['value'] = 36;
} else if ($node->field_cv_leeftijd[0]['value'] >= 40 && $node->field_cv_leeftijd[0]['value'] < 50) {
  $node_field[0]['value'] = 37;
} else if ($node->field_cv_leeftijd[0]['value'] >= 50) {
  $node_field[0]['value'] = 18;
}
$node->field_cv_lc[0]['tid'] = $node_field[0]['value'];

Hope it is a little bit clear and helps you further...
Regards,
Frank

lias’s picture

i'm wondering if this would help make a search by age range list after the user has entered their birthdate. How does the end user see this? Do you have a site that is using this code? THanks