Wordpress Rest API和自定义字段

时间:2019-07-01 12:29:05

标签: woocommerce wordpress-rest-api

我需要通过rest api访问我的自定义产品字段,但到目前为止还没有运气。 我找到了一些人建议的代码,但我认为不适用于最新版本。 add_filter('woocommerce_rest_prepare_product','wc_rest_api_add_custom_data_to_product',90,2); 函数wc_rest_api_add_custom_data_to_product($ response,$ post){

///检索自定义字段并将其添加到API响应中   $ response-> data ['custom_field'] = get_post_meta($ post-> ID,'custom_field',true);

返回$ response;

}

关于如何使它工作的任何建议,以便我可以通过Rest API访问“ custom_field”和“ custom_field2”吗?

0 个答案:

没有答案