Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 用于woocommerce类别图像的json api控制器_Php_Json_Object_Woocommerce_Categories - Fatal编程技术网

Php 用于woocommerce类别图像的json api控制器

Php 用于woocommerce类别图像的json api控制器,php,json,object,woocommerce,categories,Php,Json,Object,Woocommerce,Categories,我尝试使用json api获取一些商业数据。有了常规的wp-jasonapi,我可以使用定制的post类型“product”来获取大部分postdata,但我还需要类别数据,比如名称和特殊的类别图像。为此,我想围绕函数get_术语(“product_cat”)编写一个简单的控制器。我敢打赌,是我缺乏php oop知识,没有添加键(image)、值(image\uURL)。我尽可能只将最后一个图像对细节添加到json中,但我真的希望找到每个类别对象的这些细节,作为所有其他键、值对之间的图像值 这是

我尝试使用json api获取一些商业数据。有了常规的wp-jasonapi,我可以使用定制的post类型“product”来获取大部分postdata,但我还需要类别数据,比如名称和特殊的类别图像。为此,我想围绕函数get_术语(“product_cat”)编写一个简单的控制器。我敢打赌,是我缺乏php oop知识,没有添加键(image)、值(image\uURL)。我尽可能只将最后一个图像对细节添加到json中,但我真的希望找到每个类别对象的这些细节,作为所有其他键、值对之间的图像值

这是我的控制器:

        <?php

        /*
         Controller name: WooCommerce Category Images
         Controller description: Get Woocommmerce category images controller
         */

        final class JSON_API_woocatimages_Controller {

          public function info() {
            return array(
              'version' => '1.0'
            );
          }

           public function get_category_images() {
            $args = array(
                'number'     => $number,
                'orderby'    => $orderby,
                'order'      => $order,
                'hide_empty' => $hide_empty,
                'include'    => $ids
            );

            $product_categories = get_terms( 'product_cat', $args );
            foreach( $product_categories as $cat ) { 

            // get the thumbnail id user the term_id
            $thumbnail_id = get_woocommerce_term_meta( $cat->term_id, 'thumbnail_id', true ); 
            // get the image URL
            $image = wp_get_attachment_url( $thumbnail_id ); 
            // here i probably do something wrong.....
            $product_categories['image'] = $image;

            }
            return array(
                "WooCommerce Categories" => $product_categories
            );

           }
        }

控制器应为:

            <?php

        /*
         Controller name: WooCommerce Category Images
         Controller description: Get Woocommmerce category images controller
         */

        final class JSON_API_woocatimages_Controller {

          public function info() {
            return array(
              'version' => '1.0'
            );
          }

           public function get_category_images() {
            $args = array(
                'number'     => $number,
                'orderby'    => $orderby,
                'order'      => $order,
                'hide_empty' => $hide_empty,
                'include'    => $ids
            );

            $product_categories = get_terms( 'product_cat', $args );
            foreach( $product_categories as $cat ) { 

            // get the thumbnail id user the term_id
            $thumbnail_id = get_woocommerce_term_meta( $cat->term_id, 'thumbnail_id', true ); 
            // get the image URL
            $image = wp_get_attachment_url( $thumbnail_id ); 

            $cat->{'image'}=$image;

            }

            return array(
                "WooCommerce Categories" => $product_categories
            );

           }
        }