1

I'm using the Vocabulary 'Tags' in multiple content types.

I have a view showing 'Content Type A', and I want to have an exposed filter showing only the 'Tags' used in 'Content Type A', not every content type.

Any ideas on how this can be achieved would be greatly appreciated, thanks!

2
+50

You can use hook_form_alter to alter the exposed form:

<?php
/**
 * Implements hook_form_alter().
 */
function mymodule_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'form_views_exposed_form') {
    drupal_set_message("Form ID is : " . $form_id);
  }
}
?>

Just write some code that fetches all the used categories in content type A and compare those with the categories in the dropdown. Then, unset the categories that aren't used.

You can do this by building an array that has the same structure as the options in the drop down and then use array_intersect to get all the values that are shared over your custom build array and the options in the dropdown.

1
  • Just a few hours after I added this bounty I encountered this blogpost link with an example, you my friend full filled the requirements of the bounty so, when I can award it, it is yours. – Ramy Deeb Feb 2 '15 at 22:19
0

Here is why iLoveDrupal :)

There is a module for this functionality.

https://www.drupal.org/project/views_selective_filters

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.