我正在寻找一个SQL查询,它可以提供WordPress站点中创建的所有类别的列表及其类别ID。由于WordPress中的类别/术语关系非常复杂,请建议进行查询。
我拿到了但没用-
SELECT ID,post_title FROM wp_posts INNER JOIN wp_term_relationships ON wp_term_relationships.object_id=wp_posts.ID INNER JOIN wp_term_taxonomy ON wp_term_taxonomy.term_taxonomy_id=wp_term_relationships.term_taxonomy_id INNER JOIN wp_terms ON wp_terms.term_id=wp_term_taxonomy.term_id WHERE name=\'category\'
最合适的回答,由SO网友:amitdutt24 整理而成
我终于找到了解决办法。下面的SQL查询从WordPress表中获取ID为的所有类别的列表-
SELECT wp_term_taxonomy.term_id, wp_terms.name FROM wp_term_relationships
LEFT JOIN wp_term_taxonomy ON (wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id)
LEFT JOIN wp_terms ON (wp_terms.term_id = wp_term_taxonomy.term_taxonomy_id)
WHERE wp_term_taxonomy.taxonomy = \'category\'
GROUP BY wp_term_taxonomy.term_id
order by wp_terms.name
希望这能帮助别人。