0

In Drupal 7, I'm tying to show all the taxonomy terms from a specific vocabulary linked to the current node being viewed. I'm doing this with a new block defined in my module.

I added a field called tags in my contenttype and gave this field the whole taxanomy behavior. This made it possible to get the terms with:

$node = menu_get_object();
$node->field_tags <- array of tags to use

But, here comes the problem, this field is only there when it's set to visible in admin/structure/types/manage/page/display . But when i do that it also becomes visible in the content. If i put it to hidden it does not only get removed in the content/node view, but it's also gone from the whole $node object.

It there a way of getting the fields from the current node that are set to hidden?

Thanks, Jonathan

0

1 Answer 1

0

The field shouldn't be removed from the $node object...if it is then I'd check what custom/contrib modules you have installed that might be causing this to happen. It's not supposed to.

A sure-fire way to make sure all fields are attached to the object is to re-load it:

$node = node_load($node->nid, NULL, TRUE);

That will re-load the $node fresh from the database, with all fields attached. You do take a performance hit doing this. However, Drupal core will never have removed the field from the $node object in the first place, so if you've got some other theme/module that's doing this you'll either have to find/repair/remove it, or use a more a extreme method like the one above.

4
  • I've done the node_load trick, that did not made a difference. But now i saw that the difference between the 2 scenario's is that when my field is hidden i only have the id's of the tags in my node. Then the field is shown, i have the objects.
    – jivanrij
    Commented Jun 28, 2012 at 9:25
  • That isn't Drupal's default behaviour so I suggest you have some code/module/theme interfering with the normal node_load() functionality
    – Clive
    Commented Jun 28, 2012 at 9:27
  • I'll look in to that. Can't remember doing anything that influences the loading of nodes. Thanks for helping me on the way :)
    – jivanrij
    Commented Jun 28, 2012 at 9:41
  • No worries glad to help :)
    – Clive
    Commented Jun 28, 2012 at 9:45

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.