如何使用MySQL查询在WordPress中选择所有类别?

时间:2014-12-15 05:53:20

标签: php mysql wordpress

如何使用MySQL查询在WordPress中选择所有类别?

我正在使用此查询:

SELECT term_id as id, name as post_title, slug as post_url 
    FROM $wpdb->terms ORDER BY name

但它也会返回标签。

1 个答案:

答案 0 :(得分:8)

您可以尝试以下操作:

SELECT t.term_id AS id,
       t.name    AS post_title,
       t.slug    AS post_url
FROM   wp_terms t
       LEFT JOIN wp_term_taxonomy tt
              ON t.term_id = tt.term_id
WHERE  tt.taxonomy = 'category'
ORDER  BY name