views_get_view_result in template.php? I want global variables using view results I can't seem to get this to work..

function mytheme_preprocess(&amp;$variables) {
    global $user;
    // Classes of logged in User
    $view_result = views_get_view_result(
        'profile_page_flagged_pages',
        'panel_pane_1',
        $user-&gt;uid
    );
    // Create array
    $class_array = [];
    foreach($view_result as $item_class) {
        $class_array[] = $item_class-&gt;nid;
    }
    // Count Classes    
    $class_count = sizeof($class_array);
    $variables['classes'] = $class_count;
}


If I set string values, it's fine. But trying the view gives a 500 error. This code works fine in a tpl file.
The theme_preprocess() function is jused to preprocess EVERY SINGLE template. What you do by now: for EVERY SINGLE template you run a view (I am not sure if it gets chached during to a single page request - so it may be that you run the view a hundred times during one page request). This may hit your servers capabilities.

1.) It is bad practice to run any views in the theme layer. Please assure that on the theme level no data alteration or processing is done any more no matter if done in a preprocess function in template.php or - even worst - in a tpl-file.

2.) Please consider a better place where to add this information by views. Where exactly do you want to add the classes? Which element?