Get the raw data from a View with views_get_view_result()
I've had the chance to use a little-known function twice in the last few weeks: views_get_view_result().
This little gem does exactly what its name implies: it gets the result of a view in raw data form. The other day I used this to get a list of our top taxonomy terms for a special select list for coaches.integrativenutrition.com.
To use, just pass the view name and (optionally) the display ID, like so:
taxonomy_term_data_field_data_field_tags] = "$result->taxonomy_term_data_field_data_field_tags";
}
$form['specialties'] = array(
'#type' => 'select',
'#options' => $options,
);
?>
You will have to dpm($result);
to see the structure of the results object, as it varies from view to view. The cool thing is, it works with any view, and can be a quick way to build a complex custom query using Relationships and Views plugins instead of writing the query from scratch. The results we got for coaches.integrativenutrition.com's custom homepage was actually a "Summary" view thats sorted by the number of entries with each tag.
Tags: Planet Drupaltips