public
Created

Get Nids from Views Results into another View passively

  • Download Gist
blog.module
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
//////////////////////////////////////////////////////////////////////
// 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);
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.