如何在WordPress中左键加入wp_terms,wp_term_relationships,wp_term_taxonomy和wp_termmeta表?

时间:2017-03-29 12:30:16

标签: php mysql wordpress

出于报告目的和展平数据,我想加入所有包含与术语相关的信息的WordPress表。

我真的不会非常使用加入声明,所以我不知道该怎么做。我猜它看起来像这样:

SELECT wp_terms.term_id, wp_terms.name, wp_term.slug, wp_term_relationships.object_id, wp_term_relationships.term_taxonomy_id, wp_term_taxonomy.term_id, wp_term_taxonomy.taxonomy, wp_term_taxonomy.description, wp_term_taxonomy.parent.parent, wp_termmeta.term_id, wp_termmeta.meta_key, wp_termmeta.meta_value. 
FROM wp_terms, wp_term_relationships, wp_term_taxonomy, wp_termmeta
LEFT JOIN wp_term_relationships ON wp_terms.term_id = wp_term_relationships.term_taxonomy_id
LEFT JOIN wp_term_taxonomy ON term_taxonomy_id
LEFT JOIN wp_termmeta on term_id; 

感谢任何帮助。

1 个答案:

答案 0 :(得分:2)

我所做的只是修复您的查询。检查这是否是你需要的。

SELECT wp_terms.term_id, wp_terms.name, wp_term_relationships.object_id, wp_term_relationships.term_taxonomy_id, wp_term_taxonomy.term_id, wp_term_taxonomy.taxonomy, wp_term_taxonomy.description, wp_term_taxonomy.parent, wp_termmeta.term_id, wp_termmeta.meta_key, wp_termmeta.meta_value
FROM wp_terms
LEFT JOIN wp_term_relationships ON wp_terms.term_id = wp_term_relationships.term_taxonomy_id
LEFT JOIN wp_term_taxonomy ON wp_term_taxonomy.term_taxonomy_id = wp_term_relationships.term_taxonomy_id
LEFT JOIN wp_termmeta on wp_termmeta.term_id = wp_terms.term_id