Wordpress 使用json api获取多个自定义分类法和术语索引
我使用并且有三种自定义分类法。例如:汽车、电话和书籍。我试着把所有的分类索引都做成这样 但它不适用于多个分类法。有人知道如何获取我所有的自定义分类法和术语索引吗 以下是JSON\u API\u分类法\u控制器:Wordpress 使用json api获取多个自定义分类法和术语索引,wordpress,custom-taxonomy,wordpress-json-api,Wordpress,Custom Taxonomy,Wordpress Json Api,我使用并且有三种自定义分类法。例如:汽车、电话和书籍。我试着把所有的分类索引都做成这样 但它不适用于多个分类法。有人知道如何获取我所有的自定义分类法和术语索引吗 以下是JSON\u API\u分类法\u控制器: class JSON_API_Taxonomy_Controller { public function get_taxonomy_index() { $terms = $this->get_terms(); return array(
class JSON_API_Taxonomy_Controller {
public function get_taxonomy_index() {
$terms = $this->get_terms();
return array(
'count' => count( $terms ),
'terms' => $terms
);
}
public function get_terms() {
global $json_api;
$taxonomy = $this->get_current_taxonomy();
if (!$taxonomy) {
$json_api->error("Not found.");
}
$wp_terms = get_terms( $taxonomy );
$terms = array();
foreach ( $wp_terms as $wp_term ) {
if ( $wp_term->term_id == 1 && $wp_term->slug == 'uncategorized' ) {
continue;
}
$terms[] = new JSON_API_Term( $wp_term );
}
return $terms;
}
protected function get_current_taxonomy() {
global $json_api;
$taxonomy = $json_api->query->get('taxonomy');
if ( $taxonomy ) {
return $taxonomy;
} else {
$json_api->error("Include 'taxonomy' var in your request.");
}
return null;
}
}
// Generic rewrite of JSON_API_Tag class to represent any term of any type of taxonomy in WP
class JSON_API_Term {
var $id; // Integer
var $slug; // String
var $title; // String
var $description; // String
function JSON_API_Term($term = null) {
if ($term) {
$this->import_wp_object($term);
}
}
function import_wp_object($term) {
$this->id = (int) $term->term_id;
$this->slug = $term->slug;
$this->title = $term->name;
$this->description = $term->description;
$this->post_count = (int) $term->count;
}
}
因此,我希望json对象输出:注册的分类法作为父项,术语作为子项。是要列出所有注册的分类法,还是要列出分类法中的所有术语?我真的不明白你想要什么我想要注册的分类法作为父项,术语作为子项。输出json如下:汽车:{BMW,丰田}电话:{apple,smasung}书籍:{book1,book2}