phpdrupaldrupal-viewsorganic-groups

organic group drupal 7 views_get_views


Trying to use views_get_views on the organic groups view OG all user group content to programmatically access the view using php. I am unable to set the parameter properly. I would like to get an example of working call.

Thanks, Olivier


Solution

  • Try This:

    /* load view object */
    $views = views_get_view('og_all_user_group_content');
    /* set default display */
    $views->set_display('default');
    
    /* pass group id as argument value */
    $group_id =''; //set your group id here
    $views->set_arguments(array($group_id));
    
    /* execute view */
    $views->execute();
    
    /* result object */
    if (!empty($views->result)) {
      if (count($views->result) > 0) {
        foreach ($views->result as $result) {
          //$result contain array of data.
        }
      }
    }