I hope this is not a duplicate: The issue queue was kind of confusing to me.

I added a filter Content:_vocname_(_vocmachinename_)(selective)exposed with Views Selective Exposed Filters.

The exposed filter on the page shows me term id's like 234 or 232 instead of term name a and term name b.

Is this by design or am I doing something wrong?

Comments

imevul’s picture

Sounds a lot like this issue: http://drupal.org/node/1608498
Perhaps you can work with the supplied patch in that thread to get the taxonomy terms working.

funkytraffic’s picture

As said in this thread it does not work yet, although it is the correct solution for this problem. Therefore this is a duplicate considering that in my case it is about taxonomy terms and not node references.

It would be nice to have a hint on the project page that this alpha is not ready for usage in certain parts of this module. It took me ages to find out about this.

Besides I would like to see this function as a filter option in views since it is a very obvious goal.

infojunkie’s picture

Status: Active » Closed (duplicate)

Marking as duplicate of #1608498: Selective filters show node id instead of title when filtering on node reference fields, where the community is working to produce a patch.

danielnolde’s picture

Status: Closed (duplicate) » Active

Sorry, this doesn't seem to be a duplicate with the narrow and node-specific direction #1608498 takes.
The proposed patch there is a no solution for the problem discussed here, since it is too node specific.
What about taxonomy based filters on term_reference fields for a taxonomy based view?
A lot of use cases are not based on nodes in Drupal 7.
We need a solution that isn't dependent on a specific base table (like node) but solves this bug in general.

pzhe’s picture

I've made the following changes in views_handler_filter_selective.inc (based on ideas in http://drupal.org/node/1608498):

  function get_value_options() {
    $this->value_options = array(0 => t('Actual values will be available at run-time'));
    if (empty($this->view->selective_oids) && !empty($this->view->inited)) {
      $handler = _views_filters_selective_get_handler($this->definition['proxy']);
      $oids = $this->get_oids();
      $options = empty($oids) ? array() : call_user_func($handler, $this, $oids);
      sort($options);
      if (!empty($options)) {
        // Encode the values to keep special chars.
        $this->value_options = array_combine(array_map('urlencode', array_values($options)), array_values($options));
      }
+      // Modify value_options to include title for term node reference fields.
+      if ($this->definition['proxy'] == 'views_handler_filter_term_node_tid') {
+        foreach ($this->value_options as $tid) {
+          $result = db_query('SELECT name FROM {taxonomy_term_data} WHERE tid = :tid', array(':tid' => $tid));
+          $title = $result->fetchField();
+          if (!empty($title)) {
+            $this->value_options[$tid] = $title;
+          }
+        }
+        // resort results based on title
+        asort($this->value_options);
+      }
+      // Remove empty values
+      $this->value_options = array_diff_key($this->value_options , array("" => NULL));
    }
  }

The exposed filter shows term names for term referencing fieds and it works correctly for numeric fields.
Also it fixes a bug "Actual values will be available at run-time".

damaged45’s picture

Hello phze,

I applied the code but still showing tid. Is there anything I need to change on your code?

Thanks,

pzhe’s picture

The code changes tids on term names if the condition ($this->definition['proxy'] == 'views_handler_filter_term_node_tid') is true.
You may try to omit the corresponding if(...):

+      // Modify value_options to include title for term node reference fields.
+      foreach ($this->value_options as $tid) {
+        $result = db_query('SELECT name FROM {taxonomy_term_data} WHERE tid = :tid', array(':tid' => $tid));
+        $title = $result->fetchField();
+        if (!empty($title)) {
+          $this->value_options[$tid] = $title;
+        }
+      }
+      // resort results based on title
+      asort($this->value_options);
+      // Remove empty values
+      $this->value_options = array_diff_key($this->value_options , array("" => NULL));

But you may have problems with selective filters based on numeric fields.
Note that my selective filters are represented in a block by Better Exposed Filters module.

funkytraffic’s picture

Seems there is a new module planning to do the same:
http://drupal.org/project/viewsextras

Remove options with no results from exposed filters and optionally display the result count for each remaining filter option

khalor’s picture

The code in #5 fixes this issue for me.

casaran’s picture

The code in #5 also worked for me.
Thank you for it.

khalor’s picture

Version: 7.x-1.0-alpha1 » 7.x-1.x-dev
Status: Active » Reviewed & tested by the community

Can we get this into dev branch?

quickly’s picture

#5 worked for me. Thanks!

3cwebdev’s picture

Seconding the request to get this fix committed to dev. It works perfect for me on multiple sites.

infojunkie’s picture

Status: Reviewed & tested by the community » Fixed

Committed to latest dev, although I'm not crazy about the patch, because it hard-codes a special case in an otherwise generic code block. But as long as it helps the folks here...

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

Info

mahpari’s picture

Issue summary: View changes

Guys, I have got this problem in drupal 8.3.5, is there any solution for it!?

Regards