Home > 7 > How to query all fields of the node that is tagged with taxonomy term from a specific vocabulary

How to query all fields of the node that is tagged with taxonomy term from a specific vocabulary

November 7Hits:8
Advertisement

I'm struggling to find a way to retrieve all the node fields where a specific taxonomy is implemented. I was close to find something with this query :

$query = db_query('SELECT fci.field_name     FROM d7_field_config_instance fci     LEFT JOIN   (SELECT tv.vid, tv.machine_name     FROM d7_taxonomy_vocabulary tv     LEFT JOIN d7_taxonomy_term_data ttd     ON tv.vid = ttd.vid     WHERE ttd.tid = 76) AS tax     ON tax.machine_name LIKE fci.bundle')); 

But it seems like machine_name and bundle have different values for a same technology.

The idea is : From a taxonomy id => find taxonomy vid (vocabulary id) => find machine name of the vocabulary => find the bundles where this vocabulary is used.

Any help would be appreciated.

Answers

I think, you should check the field_config table where type = 'taxonomy_term_reference'. The vocabulary name where the field is referencing to is stored in the data column as BLOB. you can use the unserialize php function to extract the data stored in the BLOB. That's because you can't reach it with a single select query.

Try using loops and ifs :)

Related Articles

Copyright (C) 2017 ceus-now.com, All Rights Reserved. webmaster#ceus-now.com 17 q. 0.931 s.