如何使用MySQL查询在WordPress中选择所有类别?
我正在使用此查询:
SELECT term_id as id, name as post_title, slug as post_url
FROM $wpdb->terms ORDER BY name
但它也会返回标签。
答案 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