【发布时间】:2023-03-05 08:16:01
【问题描述】:
我正在使用 Wordpress REST API 来构建移动应用程序,并在(帖子类型)wooCommerce 上进行了大量自定义功能,具体而言,这使得请求时响应时间变长,例如,像这样的端点/wp-json/wc/v3/products
我的自定义是在产品帖子类型上注册新字段。
我需要检查它是否是这样的单个记录?
/wp-json/wc/v3/products/123456
或者像这样获取所有产品?
/wp-json/wc/v3/products
我的注册新字段的php代码:
add_action('rest_api_init','get_custom_field');
function get_custom_field() {
register_rest_field('product', 'custom_variations', array(
'get_callback' => 'custom_variations'
));
register_rest_field('product', 'components', array(
'get_callback' => 'product_components'
));
}
【问题讨论】:
-
我不太清楚你在问什么......还有,你的永久链接结构是什么?
-
我只需要在单个记录休息 API with id 路由中注册其余字段,所以这里在示例中
wp-json/wc/v3/product/54897不是到处都有帖子类型产品 -
你找到什么了吗? @heshamshawky
标签: php wordpress wordpress-rest-api