We are using Entity Reference.

We have a content type "Dog", and a content type "Breed". In the Dog content type, there is an entity reference field to Breed

We want to have a View that displays pictures and names dogs of a random Breed. If the page is refreshed, it should select a new random breed by which to filter the Dogs displayed. We are displaying Dogs by Breed no problem, but getting it to load (and refresh) with a Random breed (and populating the Dogs accordingly) is the challenge we cannot yet solve.

I have a feeling we need to use a PHP Contextual Filter to handle this, but not sure what the approach is to make it work properly. Does anyone have any insight here??

  • Alternatively, perhaps this could be accomplished using a module for content with Ajax functionality -- basically I'm thinking the page would: 1. Load with the single random Breed (easy using Global:Random filter and load one result paging). 2. The Ajax block (which will list the Dogs), at the end of the page load, would grab the Breed and use it to populate the dogs. Any thoughts / insight on such methodology? – Mitchell Loren Mar 2 '15 at 10:05

you just have to configure a view that:

  1. shows 1 breed, sorted random.
  2. has another display that shows dogs based on a contextual filter on the breed nid
  3. Install views field view
  4. use the block from step 2 as a field in your first display and give the nid of the breed as a contextual filter to your views field.

So this views will show one random breed and has a view field to show the dogs that are of that breed. Hope this helps you out.

  • This was very helpful, and I very much appreciate it. However, we don't seem to be able to get the filters to work correctly. It seems like we are either getting all results (not by the 1 Breed but of all Breeds) or no results at all. Is there a post or something more in-depth you could point us to? – Mitchell Loren Mar 2 '15 at 2:53
  • Can you post some screenshots of your view config? – Robin Mar 2 '15 at 6:44
  • Thanks, @Robin - but My coworker is working on the views field view method you suggested as he was already somewhat familiar with the module. However, he is giving up for the night and made no headway. I'm concurrently working on the issue trying to get it done using relationships and/or contextual filters, and not using views field view. Is there a way to accomplish it without views field view? Perhaps 1. make the page view with the single random breed (easy), 2. add block to the page showing dogs of that breed via relationship or contextual filter / using dogs' breed entity ref (no luck yet) – Mitchell Loren Mar 2 '15 at 9:04
  • Can you set up a dev environment? I could do it for you... – Robin Mar 2 '15 at 19:52
  • Hi Robin - we were able to get your solution using views field view to work! We had a missing field relationship but getting good results now... THANKS! – Mitchell Loren Mar 2 '15 at 19:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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