Quantcast
Channel: Question and Answer » hook-views-query-alter
Viewing all articles
Browse latest Browse all 26

Append more nodes to views result

$
0
0

What’s the best Views Hook and the best method to append more nodes to an already queried views result?

I wanted to build a node type (Type A) with node references to another type (Type B), and also a views view which will list node type B through a views relationship provided it gets node type A’s nid through a contextual filter. The node type A and B however also share a taxonomy term reference field for the same vocabulary.

So I wanted the person creating node type A to be able to reference a few nodes of type B, and they will get displayed at the top of the views list, however I wanted to also append the rest of the node type B with the same taxonomy terms as node type A to the views list. It is quite important that the result from querying nodes with same taxonomy reference gets appended to the result of the referenced nodes for display purposes. Because I’m using an Isotope/Packery display, they need to be in the same container with same structure.

I was thinking of also using hook_views_query_alter but it seems like it cannot be achieved through a single query, because the referenced nodes need to be ordered and appear at the top. I was thinking of using hook_views_post_execute and just simply run a db_query of my own, exclude the nodes already in the views result to grab the rest of the nodes of type B and append it to the result.

Is this possible? What are the pitfalls of such a method? I.E. paging, performance etc. Is it do-able?

Is there a better method? Is it do-able from the UI? Any pointers greatly appreciated.


Viewing all articles
Browse latest Browse all 26

Trending Articles