After using views_get_view($view_name) how do I get the names of the fields? The list of field names (arranged correctly) is going to be pushed onto an array following which will be all the results. I can see in the return value from views_get_view() the field array, but how do I get them as they would be displayed in a table, that is, correct capitalization, spaces instead of underscores, etc.?

1 Answer 1


There is an array of fields in the display object:


for example if you want to retrieve list of field names of the view arbitrary display, you'd need to do something like this:

function get_views_field_names($view_name, $display = 'default') {
   $view = views_get_view($view_name);
   $result = array();
   foreach($view->display[$display]->display_options['fields'] as $field){
       $result[] = $field->label;
   return $result;

and somewhere in the code

$fields = get_views_field_names('YOURVIEWNAME', 'YOURDISPLAYNAME');
  • Huge help, but I had to make a couple changes. I added if !isset($view->display[$display]->display_options['fields'])){$display = 'default';} in case the display is supplied but uses the defaults. Also, $field is an array not an object so I used brackets.
    – htoip
    Apr 28, 2012 at 11:10

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.