EntityFieldQuery stopped working for non-logged in users

I have a block that displays data from various nodes. It does calculations based on a few fields that exist in these ndes.

Recently it stopped displaying for everyone except user 1.

Simple solution was to make sure my EntityFieldQuery was run using the user 1 account by adding MetaData to the query.

I found this in the Drupal.org docs, but I must admit its been a while since I've had to check it out and I think it has been added since

<?php
$query
= new EntityFieldQuery();

$query->entityCondition('entity_type', 'node')
  ->
entityCondition('type', 'article')
  ->
propertyCondition('status', 1)
  ->
addMetaData('account', user_load(1)); // Run the query as user 1.

$result = $query->execute();

if (isset($result['node'])) {
 
$news_items_nids = array_keys($result['node']);
 
$news_items = entity_load('node', $news_items_nids);
}
?>

Add new comment