Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/273.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 Rest API产品过滤器如何工作?_Php_Wordpress_Woocommerce Rest Api - Fatal编程技术网

Php Woocommerce Rest API产品过滤器如何工作?

Php Woocommerce Rest API产品过滤器如何工作?,php,wordpress,woocommerce-rest-api,Php,Wordpress,Woocommerce Rest Api,我正在尝试将woocommerce rest API与我的应用程序集成。所有默认操作,如获取所有产品、按类别获取产品等,都工作得非常好 有人能告诉我产品过滤器是如何实现的吗 下面是我的密码 $data = array( 'status' => 'publish', 'category' => '51', 'per_page' => 100, 'page' => 1, 'attribute' => "Color", 'a

我正在尝试将woocommerce rest API与我的应用程序集成。所有默认操作,如获取所有产品、按类别获取产品等,都工作得非常好

有人能告诉我产品过滤器是如何实现的吗

下面是我的密码

$data = array(
    'status' => 'publish',
    'category' => '51',
    'per_page' => 100,
    'page' => 1,
    'attribute' => "Color",
    'attribute_term' => "Loft Gray"
);

$results = $woocommerce->get('products', $data)

你的问题真是无穷无尽。您没有任何代码示例可以显示您的工作情况,例如,当您说“按类别获取产品”等时,您还需要什么

我可以给你举几个例子,但谁知道它是否有用呢。我假设您已经有一个$woocmerce连接变量正在工作

示例1:

$products = array();

$data = array(
    'status' => 'publish',
    'per_page' => 30,
    'orderby' => 'date',
    'order' => 'asc',
    'featured' => 1
);

$products = $woocommerce->get('products', $data);//returns the first 30 featured products that are published, and sorts them by date
$results = array();
$data = array(
    'status' => 'publish',
    'category' => '51',
    'per_page' => 100,
    'page' => 1
    //'filter[posts_per_page]' => '-1', //this was removed in v2 api
);

$results = $woocommerce->get('products', $data);//returns 100 published products of product category ID 51 (get this ID from your CMS)
//This can be used for pagination, since the filter functionality is removed
示例2:

$products = array();

$data = array(
    'status' => 'publish',
    'per_page' => 30,
    'orderby' => 'date',
    'order' => 'asc',
    'featured' => 1
);

$products = $woocommerce->get('products', $data);//returns the first 30 featured products that are published, and sorts them by date
$results = array();
$data = array(
    'status' => 'publish',
    'category' => '51',
    'per_page' => 100,
    'page' => 1
    //'filter[posts_per_page]' => '-1', //this was removed in v2 api
);

$results = $woocommerce->get('products', $data);//returns 100 published products of product category ID 51 (get this ID from your CMS)
//This can be used for pagination, since the filter functionality is removed
API文档向您展示了您可以访问的所有不同属性:


我希望这有帮助。如果没有,那么请问一个具体的问题。

你的问题是开放的。您没有任何代码示例可以显示您的工作情况,例如,当您说“按类别获取产品”等时,您还需要什么

我可以给你举几个例子,但谁知道它是否有用呢。我假设您已经有一个$woocmerce连接变量正在工作

示例1:

$products = array();

$data = array(
    'status' => 'publish',
    'per_page' => 30,
    'orderby' => 'date',
    'order' => 'asc',
    'featured' => 1
);

$products = $woocommerce->get('products', $data);//returns the first 30 featured products that are published, and sorts them by date
$results = array();
$data = array(
    'status' => 'publish',
    'category' => '51',
    'per_page' => 100,
    'page' => 1
    //'filter[posts_per_page]' => '-1', //this was removed in v2 api
);

$results = $woocommerce->get('products', $data);//returns 100 published products of product category ID 51 (get this ID from your CMS)
//This can be used for pagination, since the filter functionality is removed
示例2:

$products = array();

$data = array(
    'status' => 'publish',
    'per_page' => 30,
    'orderby' => 'date',
    'order' => 'asc',
    'featured' => 1
);

$products = $woocommerce->get('products', $data);//returns the first 30 featured products that are published, and sorts them by date
$results = array();
$data = array(
    'status' => 'publish',
    'category' => '51',
    'per_page' => 100,
    'page' => 1
    //'filter[posts_per_page]' => '-1', //this was removed in v2 api
);

$results = $woocommerce->get('products', $data);//returns 100 published products of product category ID 51 (get this ID from your CMS)
//This can be used for pagination, since the filter functionality is removed
API文档向您展示了您可以访问的所有不同属性:


我希望这有帮助。如果没有,请提出具体问题。

1。取出“类别”=>“51”,2。属性项正在查找项ID()@Jarom我尝试了你的方法获取特色产品,但它不起作用仍然给出相同的结果,即使我在$data数组中使用了featured=>0,它也会返回与我使用的v3产品相同的10个结果api@ZaheerAhmad你能不能创建一个新问题,然后发布你的特定查询(以及你正在尝试完成的任务)?调试我看不到的东西很困难。将这个问题链接到这里,我来看看。1.去掉“category”=>“51”,2。属性term正在寻找一个term ID()@Jarom我尝试了你的方法获取特色产品,但它不起作用仍然给出相同的结果即使我在$data数组中使用了特色=>0,它也会返回与我使用的产品相同的10个结果v3api@ZaheerAhmad你能创建一个新的问题,然后发布你的不起作用的特定查询吗(以及您试图完成的任务)?调试一些我看不到的东西很困难。将该问题链接到此处,我来看看。