Description:
Scenario:
I have 2 different content types, type1 and type2. I have a vocabulary (vocabulary ID value of 4) with these terms:
-termA (the term ID is 7 for termA)
--termA1
--termA2
-termB
--termB1
--termB2
I have a field_topic content taxonomy field that is shared by type1 and type2.
Question:
What do I have to enter in the "PHP Code for selecting the parent term" box in order to limit the list of selectable terms for type1 (to only allow the user to select termA, termA1, or termA2), but show the whole list for type2?
I was thinking it would go something like this:
if($form['type']['#value']='type1' {
return '7';
}else {
return '0';
}
...but that doesn't work (it's as if the "if" function doesn't work and it returns the first value within the if statement no matter what, i.e. it limits the list for both content types).
Comments
_
Haven't seen this old chestnut of a coding error for a while :-)
if ($variable = 'value')...will assign 'value' to $variable, and return 'value' which for the string 'type1' (or any string that's not empty) is TRUE.
What you want is
if ($variable == $value)...which tests if the two are of the same value, or
if ($variable === $value)...which tests if the two are of the same value AND type.
Pete.
Thanks, but...
Thanks for pointing that out to me. I completely forgot about the whole =/==/=== thing.
Unfortunately, even with the modified ==, I still can't get it to filter correctly. Perhaps the content taxonomy function that accepts PHP code doesn't take if statements?
Has anyone successfully filtered a content taxonomy field using the PHP code box?
The first thing that comes
didnt seem to work after all :(
forget arguments
I used the following code:
which seems to work.
I see now that you didn't use
didnt seem to work after all :(
solved
Put this in your template.php
And then, in the CCK PHP field for parent term, put the following code:
Kind regards,
Izz ad-DIn
Select Parent Taxonomy by node creation and editing existing nod
Hi,
You also want to select the right parent node when editing a node. The problem is the $node object is not available to determine $node->type. But you can use other variables.
I use the following code to select the parent node. It works for node creation and editing an existing node.
Thanks to ablommers.