0

Say I have a content type, nodes, that I want to serve through a view.

The problem is, the results are based on a series of complex requirements and conditions that aren't easily controlled through the Views UI. That is, I would like to determine which nodes to output in the view in code - is there a hook I can use to effectively build up the results, which are then fed through to the 'dumb' view?

In this way, I can do all my complex querying and calculations in code, then simply provide an array or similar of objects that the view will treat as its results, and simply spit them out?

EDIT: This doesn't necessarily have to be mediated through views, it's just I can't build the query I want in views easily because it's got a lot of moving parts.

1 Answer 1

0

Use hook_views_query_alter().

Alter the query before executing the query.

This hook should be placed in MODULENAME.views.inc and it will be auto-loaded. MODULENAME.views.inc must be in the directory specified by the 'path' key returned by MODULENAME_views_api(), or the same directory as the .module file, if 'path' is unspecified

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.