What am I doing wrong. I can’t seem to pull based upon content type fields in drupal 7.
function ycs_list($number) {
$query = db_select('field_data_field_active_image', 'a')
->fields('a', array('field_active_image_value', 'entity_id'))
->condition('a.field_active_image_value', 1);
$query->join('node', 'n', 'n.nid = a.entity_id');
$query
->fields('n', array('nid', 'title', 'uid'))
->range(0, $number)
->addTag('node_access')
->execute();
print $query;
return $query;
}
This is how the query prints:
SELECT a.field_active_image_value AS field_active_image_value, a.entity_id AS entity_id, n.nid AS nid, n.title AS title, n.uid AS uid FROM {field_data_field_active_image} a INNER JOIN {node} n ON n.nid = a.entity_id WHERE (a.field_active_image_value = :db_condition_placeholder_0) LIMIT 3 OFFSET 0
It looks right and does work directly in mysql. I have to change :db_conditon_placehoder_0 to 1 and it works doing a direct sql query. I want to pull an array of nodes based upon a condition in the active_image field. Any help would be much appreciated.
Without knowing the actual error you’re getting it’s a bit tricky to debug your existing code, but I’d advise using the
EntityFieldQueryclass to do this instead: