1

I have three content types Projects, Campaigns and Blog Posts. Campaigns and Blog Posts share an entity reference field that allows for selection of one or more related Projects.

I currently have a View with block that is displayed on the individual Project nodes and lists Blog Posts that are related to that Project. There is a contextual filter to compare the array of related (Project) nodes within the Blog Posts with the ID of the current Project node. I want to add the same type of list to the individual Campaign nodes.

The Campaign nodes will have one or more referenced Projects and the Blog Posts must be compared to see if they share any of the referenced Projects in common.

For example Campaign 1 with references to:

  • (Project 1, Project 2, Project 3)

should show related Blog Posts with either:

  • (Project 1)
  • (Project 2)
  • (Project 3)
  • (Project 2, Project 3)
  • (Project 1, Project 3)
  • (Project 1, Project 2)
  • (Project 1, Project 2, Project 3)

I have read and tried a couple of possible solutions to configure the contextual filters and relationships, but nothing is working; the results are blank. I know for a fact that there is a Blog Post and a Campaign that share at least one common Project reference. So the results should show at least that one Blog Post.

Any ideas? Clearly defined configuration options would be appreciated.

1 Answer 1

0

You could get the blog posts related to projects refernced by the campaign displayed through:

1- create a view to get project id for projects have relation with that campaign.

2- create a new view listing blog posts that have relationships with projects taking project id as a contexctual filter.

3- create a .tpl file displaying the output of the view that gets projects from theme information

In that file embed blog posts view using views_embed_view() function giving the projects ids as a parameter for the view but you will need to

Configure views to accept multiple parameters you should set this option: View → Advanced → Your Contextual Filter → More → Allow Multiple Values

you will loop through fields to extract and form the ids array and pass it as the code sample below

$array = array('32+50+32');
$view = views_get_view('myview');
$view->set_display("myblock");
$view->set_arguments($array);
$view->pre_execute();
$view->execute();
$content = $view->render();

By that you will be able to get blog posts from another separated view

Your Answer

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

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