Skip to content

Instantly share code, notes, and snippets.

@twohlix
Created August 31, 2011 20:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save twohlix/1184570 to your computer and use it in GitHub Desktop.
Save twohlix/1184570 to your computer and use it in GitHub Desktop.
Get Nids from Views Results into another View passively
//////////////////////////////////////////////////////////////////////
// Get Nids from Views Results into another View passively
//
// Problem with below code is caching
// 'featured_nids' may not get updated before views_pre_view
// this will lead to an issue where the args set on 'blogs'
// will always be lagging behind by 1 cache clear.
//hook_views_pre_view
function blog_views_pre_view(&$view, &$display_id, &$args){
//dpm($view); dpm($display_id); dpm($args);
if($view->name == 'blogs'){
//get some nids to not show in the blog block
$nids = variable_get('featured_nids', array());
//append them as args
$args = array_merge($args, $nids);
}
}
//hook_views_pre_render
function blog_views_pre_render(&$view){
//if we're in this hook, something changed
if($view->name == 'home_page_feature_rotator'){
//grab nids
$view_cont = $view->result;
$to_set = array();
foreach( $view_cont as $res ){
$to_set[] = $res->nid;
}
variable_set('featured_nids', $to_set);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment