Drupal 7 Taxonomy: Find TID by custom field value - drupal

// Application
Drupal 7
// Problem Background
My website imports product data from a CSV file. I have a module that parses the file and creates appropriate nodes. In the CSV file, product category is given by category ID, which are different than Taxonomy Term IDs I have for the product categories in Drupal. I have created a custom field in my Taxonomy Vocabulary ("category_id") to link Drupal categories to imported category IDs.
When creating a node during import, I need "tid" (Taxonomy Term ID) to assign a node to a Taxonomy Term.
// The Question
How can I find Taxonomy Term ID ("tid"), knowing the value of a custom Taxonomy field?

Your custom taxonomy field ("category_id") creates a table field_data_field_category_id which should have an entity_id column/field which is your tid.

If you have command line Drush access, you could do:
drush php-eval '$tax=taxonomy_vocabulary_machine_name_load("main_site_structure");echo $tax->vid;'

Related

View: Exclude nodes that have the same taxonomy term id(s) as current node

Drupal 8
I have a content type with a field that holds a Taxonomy Term Reference. I want a View that shows other nodes of the same content type that do not have that field with the same Taxonomy Term ID as the currently viewed node.
Example:
URL: /story/storyA
Currently viewing a node of Content Type Story that has a Taxonomy Term Reference to value B. I need the view to show other stories that do not have that same Taxonomy Term Reference to value B.
I thought I could achieve that by
Set up a relationship to the field that holds the Taxonomy Term
Add a Filter Criteria of Term ID associated to above relationship and with operator is not equal to. PROBLEM: how do I get the token for Value?
I also tried to go about adding a Contextual Filter associated to the created relationship and selecting Exlude but no dice.
I finally figured it out, I was missing the adequate additional Contextual Filter:
Term ID , Provide default value with Taxonomy term ID from URL and the options Load default filter from node page and limit terms by vocab checked. And the last bit, in More, I have Exclude checked. This contextual filter is associated to the created relationship mentioned in the question.

Drupal 8 equivalent of taxonomy term converted to term id views

So in Drupal 7 it was very easy to pass a taxonomy term by name as a contextual filter and it USED to have the option of convert term name to id. What's the equivalent of that in Drupal 8? I've tried the validator as "taxonomy term name" and it doesn't work. When I try to pass it by name I get nothing, but when I do ID it works. So I don't understand how to pass the actual taxonomy term name as the filter.
You first have to create a relation with the taxonomy terms by adding the relationship with the taxonomy list or Taxonomy terms on node. Once you have added the relation, you can now add a contextual filter called name with the category Taxonomy term. This way you can pass the taxonomy term by name to the filter.

Drupal 7 taxonomy term nodes sort by WEIGHT

I've created content type called 'price' and defined field called 'weight'. Also I've created field 'Taxonomy term reference'. When clicking on Taxonomy term it shows all nodes related to this term. But How I can sort them by WEIGHT field?
At this moment I've created pages for all terms in views(I was lucky, I've got only 8 terms). But if terms would be more than 8. How can I automate this process? I would like create only one views for all terms.
Define Views for field reference -> node listing -> add relation for taxonomy term -> add sorting for this relation.

Linking tables in Drupal 7

I cant figure out how to link fields between 2 content-types in Drupal 7. For example...
I'm building an online shop using Drupal 7. There are several product categories and each category has its own page that displays all the products in that category plus a category description.
I store this data in two tables (content types). See below.
categories content-type:
category_name, description
----------------------------------------------
paintings, "A selection of paintings that we supply. Prices include ...."
ceramics, ....
jewellery, ....
.
products content-type:
name, category_name, price, ...
---------------------------------------------------
mona-lisa, paintings, £10,
necklace1, jewellery, £20,
necklace2, jewellery, £30,
.
The common field is 'category_name'. In the first table I define all the values for category_name and in the second table, each time I add a new product, I want to be able to pick one category to assign to the product. Does anyone know how to do this?
You can reuse fields between content types but you cant change the widget type (the 'categories' content-type needs free-text entry and the 'products' content-type needs a selector.
In Drupal 6 there seemed to be a 'node reference' field type which might be what I'm looking for but I cant figure out how to get this in Drupal7.
This module is still in progress but you can use references for that.

Theming order by taxonomy term

I have a view that gets all the nodes from a certain type and shows them on a page; every node is categorized by a taxonomy term.
I created a custom .template file to theme the view using the row style, but what I really would like to do is order all the nodes under a category, for example:
category 1
node 1
node 7
node 15
category 2
node 2
node 6
How do I do this?
Please note steps describe below are for D6:
Create u r view using drupal views module
Select the appropriate fields,
under filter field, Select the taxonomy , and select appropriate taxonomy term
Select the appropriate fields (which you will like to display).
change the output style to table or whatever you prefer
and there you have it
Hope it helps.

Resources