Ali Raza
Ali Raza

Reputation: 183

get wordpress categories list from custom query

I am writing a web service and I need to fetch list of all categories of Wordpress in JSON response. Has somebody already done this? Please share the solution.

Upvotes: 1

Views: 981

Answers (1)

Deepak saini
Deepak saini

Reputation: 4270

Here is the function of all categories list in json format. I hope it will be work.Please try this :-

<?php 
        function get_all_categories(){
            $args = array(
            'type'                     => 'post',
            'child_of'                 => 0,
            'parent'                   => '',
            'orderby'                  => 'name',
            'order'                    => 'ASC',
            'hide_empty'               => 1,
            'hierarchical'             => 1,
            'exclude'                  => '',
            'include'                  => '',
            'number'                   => '',
            'taxonomy'                 => 'category',
            'pad_counts'               => false 

        ); 


            $categories = get_categories( $args );
            return json_encode($categories));
      }
    ?> 

Upvotes: 2

Related Questions