I'm coding a block that will display all the nodes that are linked to the same term of the node that is currently rendered. I'm using this code:

$mynode = node_load(arg(1));
$results = taxonomy_select_nodes(array($mynode->taxonomy[1]->tid));

This, however, only works for nodes linked to term 1... I'm wondering why the index of the taxonomy object in that array is the same as its id and not just an incrementing index...

Can anyone tell me if this is by design, and if so, maybe a short explanation why and how I would go about to getting the first element of the array (not necessarily the element with index 1) without removing and adding it again with array_shift and array_unshift?

Comments

ainigma32’s picture

Status: Active » Fixed

I don't know why the index of the taxonomy array is filled with the ids of the terms but you can use key($array) to get the key of the current array item. See here http://www.php.net/manual/en/function.key.php
To make sure you are at the first item you can use reset: http://www.php.net/manual/en/function.reset.php

- Arie

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.