我使用json-api 插件,我有三个自定义分类法。例如:汽车、电话和书。我尝试让所有分类索引都像这样
http://example.com/api/taxonomy/get_taxonomy_index/?taxonomy=car,phone,book
但它不适用于一种以上的分类法。有谁知道如何获取我所有的自定义分类法和术语索引?
这是 JSON_API_Taxonomy_Controller:
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 对象输出:注册分类法作为父项,术语作为子项。