I am working directly with MySQL, using MySQL workbench. Can you help me write a SQL query that will pull all custom taxonomies and their term-meta fields?
I have a custom taxonomy called(slug) census-tract
and a few custom fields attached to each:
census-tract-income-level
census-tract-population
How would I go about joining the following tables
wp_terms
wp_termmeta
wp_term_taxonomy
to find WHERE wp_termmeta.meta_key = 'census-tract-population' AND wp_termmeta.meta_key = 'census-tract-income-level'
?
Thanks!!
I am working directly with MySQL, using MySQL workbench. Can you help me write a SQL query that will pull all custom taxonomies and their term-meta fields?
I have a custom taxonomy called(slug) census-tract
and a few custom fields attached to each:
census-tract-income-level
census-tract-population
How would I go about joining the following tables
wp_terms
wp_termmeta
wp_term_taxonomy
to find WHERE wp_termmeta.meta_key = 'census-tract-population' AND wp_termmeta.meta_key = 'census-tract-income-level'
?
Thanks!!
Share Improve this question asked Jun 9, 2017 at 21:08 italiansodaitaliansoda 4261 gold badge6 silver badges14 bronze badges 4- do you want the taxonomies or the terms, along with the termmeta, and do you want all, or just the one you mentioned? – inarilo Commented Jun 10, 2017 at 21:15
- Just the one taxonomy I mentioned along with all of it's termmeta. – italiansoda Commented Jun 10, 2017 at 21:17
- but term meta is term specific, not taxonomy specific – inarilo Commented Jun 10, 2017 at 21:24
- Ah, gotcha. I'm a little fuzzy with how the relationship/hierarchy goes. So let's try this again, SQL for .... just the one taxonomy for all of it's terms and each term's termmeta. – italiansoda Commented Jun 10, 2017 at 21:31
1 Answer
Reset to default 1Try
select t.name, t.slug, tm.meta_key, tm.meta_value
from wp_term_taxonomy AS tt
inner join wp_terms AS t ON tt.term_id = t.term_id
inner join wp_termmeta AS tm ON t.term_id = tm.term_id
where tt.taxonomy = 'census-tract'
order by t.name