WooCommerce Rest API 通过 slug 获取产品 [英] WooCommerce Rest API get products by slug

查看:47
本文介绍了WooCommerce Rest API 通过 slug 获取产品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

WooCommerce 的新手,并使用 REST API 获取我已成功完成的产品.

New to WooCommerce, and using the REST API to get products which I have successfully done.

不确定如何使用 slug 获取单个产品,因为永久链接提供了完整的 url,因为我只需要结束 slug,所以我可以拥有干净的 url,而不使用 id 查找记录.我知道使用 Wordpress rest api 插件,您可以执行此操作 posts-api?filter[name]== 并通过产品 slug 获取帖子,而不是使用:

Not sure on how to get a single product using the slug as permalink gives full url, where as i only need the end slug so I can have clean urls and not use the id to find a record. I know with the Wordpress rest api plugin you can do this posts-api?filter[name]== and get the post by product slug, rather than use:

/wc-api/v3/products/id

我希望能够做到:

/wc-api/v3/products/slug

推荐答案

你只需要稍微调整一下查询 /wc-api/v3/products/slug 应该是 /wc-api/v3/products/?slug=your-product-slug.

You just have to adjust the query slightly /wc-api/v3/products/slug should be /wc-api/v3/products/?slug=your-product-slug.

一个重要的区别是,这将返回数组内的 slug,因此您必须在解析它后选择数组中的第一个对象.

One important difference is that this will return the slug inside an array, so you will have to select the first object in the array once you have parsed it.

这篇关于WooCommerce Rest API 通过 slug 获取产品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆