Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用MySQL查询选择WordPress中的所有类别?_Php_Mysql_Wordpress - Fatal编程技术网

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

Php 如何使用MySQL查询选择WordPress中的所有类别?,php,mysql,wordpress,Php,Mysql,Wordpress,如何使用MySQL查询选择WordPress中的所有类别 我正在使用此查询: SELECT term_id as id, name as post_title, slug as post_url FROM $wpdb->terms ORDER BY name 但它也会返回标记。您可以尝试以下操作: SELECT t.term_id AS id, t.name AS post_title, t.slug AS post_url FROM

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

我正在使用此查询:

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

但它也会返回标记。

您可以尝试以下操作:

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