To overcome the lack of UNION support in Views, I use the trick suggested by merlinofchaos in #1013774: Is there ANY way to combine results? (Pls view attachment) - "use hook_views_pre_render(), execute an alternative display (recommend an attachment that is not actually attached to anything), then merge $view->result."
I have several page displays that could use almost the same attachment, so I was hoping I could do something like:
$other_view = views_get_view('my_view', TRUE);
$other_view->set_display('attachment_1');
$other_view->build();
// Modify WHERE clause depending on which page display is used:
if ($view->current_display == '...') {
$other_view->query->where [....]
}
else {
$other_view->query->where [....]
}
$other_view->execute();
$view->result = array_merge($view->result, $other_view->result);
but it doesn't work. Neither does $other_view->query->add_where ... The executed query is still unaltered.
Apparently, the query is built and stored somewhere else - in the SelectQuery object in $other_view->build_info['query'] maybe - and $other_view->query is just kept for reference (and not used when executing the view). Am I right? If I'm right, this could be made clearer in the documentation of the build function.
And finally - the real question: Is there a workaround for my use case? (I don't see how I can use hook_views_pre_execute since the modifications depends on my page displays and not something in the attachment itself.)
Comments
Comment #1
MustangGB CreditAttribution: MustangGB commentedClosing this as outdated, feel free to re-open if you're still looking for a solution and waiting for appropriate assistance.