最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

terms - MySQL query for taxonomy-meta

programmeradmin2浏览0评论

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
Add a comment  | 

1 Answer 1

Reset to default 1

Try

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
发布评论

评论列表(0)

  1. 暂无评论