I am trying to pull the "playablefiles" URIs from the array for a video field (hereafter: field_video).

Here's a look at how the array is set up.

I'm trying to pull a list of the files by this method, which seems to be in error:

  foreach($node->field_video['und']['0']['playablefiles']) {
    echo $node->field_video['und']['0']['playablefiles']['uri'];

Can anyone tell me what I'm doing wrong here?


There are a few things that could do with attention...

  • A foreach statement needs an as keyword to keep a reference to the current object in the iteration (the docs explain it better than that, it's worth having a read). This error should throw an exception.
  • From the looks of the array each 'playablefile' is an object (not an array) so you need to access its members with -> not []. If the interpreter makes it this far this should also throw an exception.
  • You can also make use of the API and make your code language safe using the field_get_items() function

The resulting code should be:

$field_items = field_get_items('node', $node, 'field_video');
foreach ($field_items[0]['playablefiles'] as $file) {
  echo $file->uri;
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.