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.

Related posts

1 comment

  1. 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));
          }
        ?> 
    

Comments are closed.