Views of content is having two contextual filter. For some reason node object is available to views so it is passing through url's 7th argument.

1.Content: Has taxonomy term ID Configuration: Php Code

$nid = arg(7);
$node = node_load($nid);
if($node && isset($node->field_tags)) {
      $related = field_get_items('node', $node, 'field_tags');//dpm($related);
      foreach($related as $tag) {
          $view_par[] = $tag['tid'];
return implode(',', $view_par);
return 0;

2.Content: Nid (Ref: entity-reference-and-nested-arguments-in-views)

$nid = arg(7);
$node = node_load($nid);
$Related_ids = array ();
    $Related = field_get_items ('node', $node, 'field_some_er')    // Get the entity reference scope
    if ($related && is_array ($related) && sizeof ($related)> 0) {
      for ($i = 0; $i <count ($related); $i++) {
        $ Related_ids [] = $related[$ i]['target_id'];
    return implode ('+', $related_ids) // It returns the values ​​of the field entity reference


Content: Taxonomy terms on node (Require this relationship :TRUE)
Content entity referenced from field_er_in_content (Require this relationship :TRUE)

With above configuration/modifying how to retrieve views's data only when

1. Any one of the filter should be present i.e either field_tags(term reference field) or field_some_er (entityreference field)
2. Both filter could be present.

but should not retrieve when both value is absent. Is there something can be done using common variable like found flag that can be shared to both php code and break the view operation.

1 Answer 1


Perhaps this is what you're looking for: https://www.drupal.org/node/1871388

Otherwise, it looks like you might want to set up what your contextual filters do when the arguments are not available:


enter image description here

  • nid is always present in URL but view should run only when any one of the two filter present. These two are fields of node whose nid is always passed through URL.
    – kiranking
    Jul 9, 2014 at 19:11

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.