Filtering a glossary view - drupal

I have a glossary view, which is just the one that comes with Views. I want to allow users to filter the results by taxonomy terms (dropdown) and also by title (search field). The problem I'm running into is that when I click on a glossary letter (e.g. X) then I try to type in a search term that begins with something other than X (e.g. Cat) I get no results. The title search filter is basically just searching within the selected letter in the Glossary. So if I'm on the X page and I search for Cat nothing is found. If I would search for X-ray then that would appear.
Is there any way to make the title filter relatable to the entire view result and not just things that begin with the glossary letter than I have selected?
In the attachment of the view I've tried turning on the "Inherit exposed filters" option but that does not help.

This happens because the view has already a Contextual Filter in use that is filtering the query from the path arguments. That means that the exposed filter is adding a filter after the main filter from the path.
First of all, enable the "Show the SQL query" option on your views settings (admin/structure/views/settings). This way you will be able to see immediately what is going on.
Furthermore, you can set the contextual filter for the title for the Page views as
"WHEN THE FILTER VALUE IS NOT IN THE URL -> Display all results for the specified field" because by default it shows titles beginning with letter "a" in the first load.
So to achieve this you should remove any path argument that exists in the path due to the contextual filter (eg for the domain.com/l?title="some title here" you must have domain.com/?title="some title here", without the "l").
You could do this with the following methods:
Override Views Contextual Filter in View Exposed Form Validation
Redirect the page removing the last path argument, eg with Rules module or a drupal function
Use the fresh filter_harmonizer module!
And the winner is probably the filter_harmonizer module.

Related

Drupal 7 views - how to combine a contextual filter with a regular filter (with OR)?

Ok, so I have a "playlist" content type, with a node reference field and a boolean field called "always display this playlist".
I have a "playlists" view with a contextual filter based on the node reference. So, when I go to "/playlists/35", it shows all the playlists that reference node 35.
All good so far.
One extra requirement is that the view needs to also display all the playlist that have the "always_display_playlist" field set to 1 (that's the boolean field).
So basically the view needs to display playlists that match the contextual filter OR that have the boolean field set to 1.
So far I have failed rather miserably in making that work. The contextual filter works great, but of course it will only display playlists that have the node reference matching the argument. How can I combine the contextual filter with another regular filter, but with "or"?
Thanks a lot for any clue or idea!
Option 1
Consider the Views Contextual Filters OR module, which only has a dev version today. Excerpt from its project page:
... provides a views plugin which modify query to support OR conditions for contextual filters.
Option 2
Otherwise the Views EVI (Exposed Value Injector) module, which only has a beta version today. Excerpt from its project page:
This module solves the fundamental and longstanding problem (#357082: Pull filter value from an argument? & Itangalos Sandbox) of views argument filters (=contextual filters): they are far less potent than regular filters.
It does this by allowing to wire argument tokens to exposed filters and optionally hide them. It also allows new use cases, think: use one exposed widget for two filters.
Credits (for Option 2): Hubert
If you click on the dropdown beside filters you could potentially use two different filter groups, one that corresponds to the contextual filter and manage it with views filter harmonizer and the other group with the boolean filter and have the OR between them.

Drupal 7 Views: Combine exposed filter with contextual filter?

Is there a way to make an exposed filter and contextual filter play nice with each other? I have the title field set as my exposed filter and then I also have a contextual filter in glossary mode. When I do a search with my exposed filter it works normally until I click on one of the letters for my contextual glossary.. then I get no results.
For example when I first come to my page it shows me that there are 35 records for the letter P. if I do a search for the word Christmas I get some results on the page but the number of records for the letter P still says 35. When I click on the letter P I get 0 results because the view is still being filtered by the word Christmas.
Is there anyway to make these two things play nicely with each other to get some results that make a little more sense? It would be nice if I clicked on a glossary letter than the exposed title filter would be reset.
Enable the filter_harmonizer module (Actually this module was publish after the question date)
(optionally) Disable AJAX for the views and set the contextual filter:
"WHEN THE FILTER VALUE IS NOT IN THE URL -> Display all results for the specified field" because by default it shows titles beginning with letter "a" in the first load.
You should try with changing the 'AND' for your filters to 'OR'
By default, if you check the added filters, they are added with 'AND' condition. So, each time you filter the result, its 'AND'ed with previous query.
Regards.

Drupal VIews Exposed Filter: Taxonomy Select List?

Drupal 6: I have a view (version 2) with an exposed filter on taxonomy term name. The provided exposed widget is a text field with 'Apply' button. What I'm trying to do is to have a drop down populated from a specific vocabulary ('Provinces' vocab consisting of terms 'BC', 'AB', 'SK', etc.), not a free text field.
I thought once I expose the filter I would get the option for a select list, but I don't. All I get is 'Operator (Is equal to, Is not equal to, etc.)' - 'Value (blank field)' - 'optional (check box)'...
I thought that this would be a pretty common thing to do but all my google-ing has found no answer.
Anybody know of a way to do this?
You have to expose the The taxonomy term ID not the The taxonomy term name in order to get the little gear icon so that you can get the drop-down.
I've using better_exposed_filters.
Click settings icon for exposed taxonomy filter and check "Dropdown list"!
just add vocab and terms
there are two areas where you can configure your taxonomy filter. First the "basic" settings, which include all settings you mentioned, and second the settings behind the "gear-icon", where you can chose your vocabbulary and the type of widget.

Drupal Views and exposed filters - how to reset optional drop-down list filter, or allow "all" selection

I have a view with a filter by country. Country is an optional CCK text field with drop-down list selection from a predefined list.
When I expose the field as an optional view search filter, I can select a country on the filter form just fine, but how can I handle no selection? I want the user to be able to "un-select" any previously selected value so that the query runs for all countries (or, to be more precise, does not constrain the results by country). I cannot add "all" as a value to the CCK field for obvious reasons. Selecting all countries in the drop-down on the search filter is not very user-friendly and causes the page to time out (there are over 200 countries in the list, and I can only imagine the resulting SQL query). Whats the best way to handle this?
I found this View Filters Reset hack which could be helpful. The desire to memorize the last selection adds another complication - when configured in the View properties, and once the (persistent) cookie is set, there is no way to get rid of the selection (short of manually deleting the cookie).
The answer was to check "Force Single" on the filter properties. This made <any> show up as a selection in the country filter drop-down. It kind of makes sense, because <any> in a multiple-selection list could be seen as ambiguous. Still, I can think of valid reasons why a multiple selection filter might be optional. Drupal surprises me every day.

Drupal Views: Get nodes with the same taxonomy as the current node

I have a Content-Type with taxonomy-terms. It's a select-list, so it can have only one taxonomy - at least of that vocabulary. Now I need to build a view that lists all nodes with the same taxonomy.
Thought that this wouldn't be too hard since it sounds pretty basic. Yet I can't get it working. Any ideas? I'm trying to avoid writing a module for this.
While this was technically possible with Views 2 as described in some of the other answers, Views 3 has this integration built in.
You can create an argument for the taxonomy term id and then choose "Provide default argument". This will then give you an option for "Taxonomy Term ID from URL" and "Load default argument from node page..."
This will allow you to take the taxonomy of a page and pass that as an argument to your view block.
Note: Views 3 is currently in Alpha 3 but in my experience is at a relatively stable state and I am using it on production sites. If it has features like the one above that you find useful please use it, test it and submit bugs/patches if you encounter any issues!
This answer works in Views version 2 or higher. First you need to install Views attach ( http://drupal.org/project/views_attach ). Please read about Views attach before proceeding further. Views attach is best explained by this video http://mustardseedmedia.com/podcast/episode37
Now we get to Views attach. Please enable the views attach module before proceeding. Essentially Views attach attaches a view at the end of the node. In our case our view will be a listing of other articles with the same term.
We will essentially need to "pass" the taxonomy term of the node to the view. Let the name of your Vocabulary be called MyVocab.
Steps to make the view.
Lets call the view display_other_articles_with_same_taxonomy.
Add a display of type Node Content (available after enabling Views attach). This is a display just like block and page displays but with special ability of attaching itself to the node.
Make the following settings in the Node Content Display
Node content settings
Node types: [select the content types you are interested in seeing the list of nodes with same taxonomy term]
Build modes: Teaser, Full node
Arguments: token
Show title: No
You should select Use tokens from the node the view is attached to under Arguments. Let the token be [term-id] This is the "ID of top taxonomy term". This is very important!! Essentially you are going to be passing the taxonomy term of the node from the MyVocab (See http://groups.drupal.org/node/11788#comment-38332). If it has the lowest weight, the taxonomy vocabulary will be the first vocabulary in the taxonomy section of your node edit form. Add an argument Taxonomy: Term Id.
Add the fields you are interested in e.g. Node: Title. Make sure the Node: Title is made into a hyperlink by ticking Link this field to its Node
So what this view is going to do is:
Take the taxonomy term from the MyVocab vocabulary in the Node that is currently being viewed
Pass that as argument to the view display_other_articles_with_same_taxonomy
List all the nodes that have the same taxonomy term as the node being displayed.
Thats it!
If you're using Views 3 (currently at alpha3 at the time of writing) and you want a block (right now the articles have same taxonomy term come at the end of node body) you can do it in the following fashion:
Forget about views attach... its not required
Add a block view. It should contain the same argument, fields and filters as the instructions above for the Node Content display.
You need to modify the settings for the argument Taxononomy: Term Id just slightly: Under Action to take if argument is not present: choose [x] Provide Default Argument. Choose [x] Taxonomy Term ID from URL. Now make sure [] Load default argument from term page is unselected and [x] Load default argument from node page, thats good for related taxonomy blocks. Also [x]Limit terms by vocabulary and choose the Series vocabulary.
Make sure you name the block and put it in the appropriate region.
Note: This answer is subset of the answer I provided at How to just show NodeQueue block on included nodes? In that scenario the requirement was that the related articles are explicitly selected and listed in a particular order. Its a little more complex and uses Nodequeues which we don't need here at all.
Use relationships
Node 1 -> Relationship 1 -> Term // This will be relationships->taxonomy->term
Term -> Relationship 2 -> Node 2 // This will be relationships->node->node
Argument NID to filter NODE 1
Fields or node full view on Relationship 2 (you will see select box on field adding form, to determinate what NODE to use)
Views gives you the options to add filters. Click the plus sign in the filters area of the views admin UI, select Taxonomy from the list, check either Term or ID, and fill in the value that you need to filter by.
EDIT (for explicit instructions):
First, add the necessary fields that you want under the fields section that you want to display from the nodes that you are trying to filter such as node title, etc.
Under Arguments, click the plus sign and select Taxonomy
Check Taxonomy: Term and click Add
Click Update
In your preview area test it out by adding an argument and clicking preview. If it doesn't work, your nodes do not have attached taxonomy, your views module is corrupted, or you didn't follow directions.

Resources