Views 1: Filter by custom table/field (or using Argument Hand. Code) - drupal

I have a page which should list nodes. The views is called from a locality page (a taxonomy term page). What I need is almost the same as using the Taxonomy: tid in arguments and passing the tid.
I can't use the term_node table, as (for other reasons) we have a custom table term_node_hierarchy (with nid and tid only). The table term_node_hierarchy is like term_node but also saves the tid of the parents (from an "external" code)
I've been looking for options but still no joy.
Currently I'm building an array of the nid's that should be displayed on the current page, and passing them like print views_build_view('embed', $view, $matching_nids); but the Argument Node: ID states This argument is a single Node ID. As said, only the first node is displayed when printing the views. It would be great if it could filter on more than one nid.
I'm open to any kind of suggestions on how to do this.
Thanks

You could create your own module for this. You could populate the $page_content variable with the results of your own custom query where you allow the user to sort against multiple nids. You could do this a number of different ways. You could display a list of the existing nids with corresponding checkboxes, so that, when the user clicks submit, all the nids that match the selected checkboxes get used in the query. Then you just display the result of that query. That's the easiest way I can think of to offer that degree of flexibility.

Related

calling of one taxonomy from another taxonomy, so both of them have used in the same content type

Can we call one taxonomy term from another as a parent and child relation for example I need to click on product category and that show me product series page and when I click on product each series that will lead me to actual product detail means node, so I have two taxonomies category and series I am about to click on category to carry me to series page and then to click on series page to carry me to product detail page on the concern series”
no codebase problem
i am expecting that these two taxonomies may be used as i have mentioned in the question summary but, i can't do it so i hope some help in resolving this issue
Let's look at this answer, I hope it will help you.
Taxonomy terms from the same vocabulary filtered and referenced on multiple content types
To do this you’ll need to have the Entity Reference module installed. So get that out of the way quickly with drush dl entity reference -y and drush en entityreference -y if you haven't already.
First up, we need the taxonomy set up.
Let's demonstrate with the help of an image.
You’ll notice that these terms could be more or less grouped into two categories: Transport and Sleeping. One term (couchette) kinda fits both criteria and is there to exemplify the reason for not using 2 different vocabularies to handle the issue. Now we need to technically make the distinction between these terms as well and since they are entities, we can use a field for that.
So we can now go ahead and add a new field to this vocabulary of the type List (text) with whatever widget you’d like (and let’s call the field Type). You should make the allowed number of values unlimited and put the following in the allowed values list:
Edit each term and select the appropriate type. As expected, for the term couchette, you should select both options.
Now that we have our taxonomy squared away, it’s time to create a View that will handle the filtering of these terms. Because if we now add the Tags taxonomy term reference field to our content types in the normal fashion (as it is already present in the Article content type) we’ll be able to select all the terms in the vocabulary for all the content types. And that's not what we want now.
So create a drupal 7/8 View that shows taxonomy terms of the Tags vocabulary - let’s call it Tags Filter. Add 2 displays of the type Entity Reference and a filter of the field we added to our terms earlier. So for instance the first display can show the terms which have Sleeping selected and the other one can show terms which have Transport. Save the View and you can close it.
Now finally we can edit our content types and add to each a new field of the type Entity Reference with a select list widget. For the target type select Taxonomy term and under Entity Selection choose the following: for Mode, go with Views: filter by entity reference view and then select the View in question - one of the two displays which we created earlier. In the picture below, I named one of the displays

Advanced Custom Fields - Filtering a Post Object Field by previously chosen Taxonomy

I have a custom post type called Event in which I want to add a location chosen from a large list of locations. To make this process easier I want to filter these locations by a category called locality.
To achieve this I have created a custom post type called Locations and a custom taxonomy called Locality. A field group holding two dropdowns one for Locality (Taxonomy) and another for Locations (Post Object) has been added to each event.
What I haven't managed to achieve is the filter of locations by the locality chosen.
I don't believe you can dynamically filter the choices of one custom field based on the current choice of another, and change that choice on the adminend. You can filter the choices that show up in your fields with a query modification that's very similar to WP_Query, and I'm pretty sure that can't be done on the fly.
I would almost cheat and instead of making posts with taxonomy assigned to them, include both the locality and the location in the post name itself.
So say, post [Museum of London] with taxonomy [London]
would become
[London][Museum of London]
[London][Hyde Park]... etc
or something similar. I'm presuming you only want to assign one location to any specific locality...
Then I'd create a relationship field and whenever I'm looking for Museum of London I'd type
London Muse...
It looks like this question is stale by now, but you would make your life easier if you added two custom fields to Event - location and locality. That way you don't have to join two tables and can easily use WP meta_query to filter posts.
What i understood is that you want that whenever you select the locality the location for it should be shown there and at last you can filter Events with locations.
=> To set location you assigned two drop-down for locality and location. You should use ajax. when i select any locality than the next drop-down has the options for the selected locality.
=> To add value in event post: you might have two options
i) you may add location as taxonomy and search using "tax query" to filter
ii) add location as parent of event and search "child of" in wp_query to filter
You have two options:
Program custom js to filter the locations field onchange of the localities field. This would not be so hard to do, because ACF sets the field id's for every field in their html. You can enqueue this js script in an admin hook (probably admin_enqueue_scripts, check this solution) and filter for the custom post type.
It can all be done in the ACF gui, but it's a bit of a trick, also because of the fact that the conditional logic for acf's taxonomy field is lacking. What you have to do is create as many Location fields in the Event acf fields as you have localities. Then set these locations to specific localities. Now comes the weird part. You would want to set the conditional logic to display if the locality is e.g. Russia, but it lacks a 'specific value' field. So you have to set two rules, one to set the 'greater than' and one to set the 'lesser than' for the id of the locality. . This will be a pain if you have a lot of localities, but it might be a good option if your localities list has no more than a few items. If you name the location fields all 'location' than you can just get the value with get_field('location'). I tested this and there is no conflict in naming all the location fields location. ACF has done a pretty decent job there, having unique names for these fields also to be able to name these fields as you whish.

Drupal: Creating a view that retrieves related nodes based on terms

I'm trying to wrap my head around getting nodes that share the same taxonomy terms, but I have some questions.
Essentially, I want to display a view at the bottom of my event node that shows related events. I have tags for each event and will be using those to create the match.
In views, when I create a taxonomy argument and add multiple "tags" it searches for nodes with all the specified arguments. What I want is not to search just for nodes that contain all of the arguments, but nodes that contain either or. So far I haven't figured any solutions.
Edit:
Would it be easier to create a simple block module that queries the database for nodes that contain the terms?
I am using a Taxonomy Term ID as argument and then I selected the checkbox that allows Multiple Terms per argument. Notice the help text that says, "If selected, users can enter multiple arguments in the form of 1+2+3 (for OR) or 1,2,3 (for AND)." By using the + sign you will OR the arguments together, but if you use the , then they will be AND together thus forcing nodes to have all terms. For this specific view I am providing the default argument via php and I am using the plus sign to wrap the term ID arguments together. This will give me all the nodes that are tagged with any of the terms supplied as arguments.
edit: I might want to also add that I have the checkbox selected for "Let Multiple arguments work together." That may or may not be needed for your use case, but I needed it for mine.

Add view filter to retrieve content associated with one or more Taxonomy Term IDs

I have created a Drupal 6 view which has two "Taxonomy: Term" (Term ID) filters, for two different taxonomy terms. I need to create a feed that pulls content that is associated with a OR b, or that is associated with a AND b. Currently, nothing is displayed because it seems that the logic of two filters is AND, not OR.
How do you pull content that has the logic OR with Drupal views?
It does work if there is only one filter, but as soon as I add a second filter, zero records are found.
The OR filter is not built in to Views2. For ways to get around this, see http://groups.drupal.org/node/16173. And this old post might help as well OR operator in Drupal View Filters

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