How to get a list of categories / tags in the Wordpress REST API

Does anyone know how to get a list of categories in the Wordpress JSON Rest API? It seems that the current API does not support retrieving a list of categories (while XML-RPC does).

http://developer.wordpress.com/docs/api/

+4
source share
6 answers

Im trying to make an andriod application from my Wordpress site. Thanks to the JSON API, which was possible, but got a real puzzle. There was no documentation for the query syntax.

After 2 hours of research, I finally dug up something. The first thing to know is there are 3 types of request mode:

1. Implicit mode

The JSON request uses a non-empty value ie "json = 1". Examples:

2.

JSON i.e "json = get_recent_post". :

3.

JSON, i.e "/api/get_recent_post". :

, :

http://blog.example.com/?json=get_category_index

:

. , -, Wordpress, .

+4

<?php echo get_the_category_list(); ?>

0

JSON API, Jetpack, . API (, , ), . , .

http://public-api.wordpress.com/rest/v1/sites/ $site/categories . .

http://developer.wordpress.com/docs/api/

0

:

  • wordpress: JSON API wordpress plugin JSON API
  • get_category_index api, : http://www.example.com/api/get_category_index

:

{
    "status": "ok",
    "count": 332,
    "categories": [{
        "id": 4637,
        "slug": "soft_360",
        "title": "360",
        "description": "",
        "parent": 4618,
        "post_count": 2
    }, {
        "id": 4498,
        "slug": "amazon",
        "title": "Amazon",
        "description": "",
        "parent": 3390,
        "post_count": 29
    }, {
    ......
    }, {
        "id": 860,
        "slug": "default_classification",
        "title": "\u9ed8\u8ba4\u5206\u7c7b",
        "description": "",
        "parent": 17,
        "post_count": 3
    }]
}

: JSON API - WordPress

0
$args = [
    'taxonomy' => 'category',
    'hide_empty' => 0,
    'parent' => 0
];

function _get_child_terms( $items ) {
    foreach ( $items as $item ) {
      $item->children = get_terms( 'category', array( 'child_of' => $item->term_id, 'hide_empty' => 0 ) );
      if ( $item->children ) _get_child_terms( $item->children );
    }
    return $items;
}

$terms = _get_child_terms( get_terms( $args ) );
echo json_encode( $terms );
0
source

All Articles