wordpress-rest-api

Woocommerce get_products return empty objects

妖精的绣舞 提交于 2021-02-11 17:42:20
问题 I'm building custom endpoint using Woocommerce Products and the query return 6 objects but empty don't now why is that? what I'm missing on my code below? Code add_action('rest_api_init', function () { register_rest_route( 'hash', 'related-products',array( 'methods' => 'GET', 'callback' => 'hash_realated_products' )); }); function hash_realated_products() { // Get 10 most recent product IDs in date descending order. $query = new WC_Product_Query( array( 'limit' => 6, 'status' => 'publish',

Update WooCommerce product price and stock

和自甴很熟 提交于 2021-02-11 06:09:45
问题 I have external REST API, from which I'm building an array like this: $arr = array( 1 => array('code' => '0100686', 'qty' => '2', 'price' => '65.22'), 2 => array('code' => '0100687', 'qty' => '1', 'price' => '5.23'), 3 => array('code' => '0100688', 'qty' => '8', 'price' => '0.28') ); After this, I need to update the price and qty of products in WooCommerce. (In above array code is SKU in WC). Afterwards my code goes following way: foreach ($arr as $single) { $product_id = wc_get_product_id_by

Update WooCommerce product price and stock

人走茶凉 提交于 2021-02-11 06:08:53
问题 I have external REST API, from which I'm building an array like this: $arr = array( 1 => array('code' => '0100686', 'qty' => '2', 'price' => '65.22'), 2 => array('code' => '0100687', 'qty' => '1', 'price' => '5.23'), 3 => array('code' => '0100688', 'qty' => '8', 'price' => '0.28') ); After this, I need to update the price and qty of products in WooCommerce. (In above array code is SKU in WC). Afterwards my code goes following way: foreach ($arr as $single) { $product_id = wc_get_product_id_by

Get WordPress Submenus in Gatsby JS

ぐ巨炮叔叔 提交于 2021-02-08 07:34:43
问题 I am fiddling around with Gatsby JS using WP as the backend and so far so good. Now I was trying to pull in the menu which for main menu items works just as expected. What I can't really wrap my head around is how to get the submenus pulled in. The only related thing I found was https://github.com/gatsbyjs/gatsby/issues/2426 which does give me the submenus if I log the data. Just can't get them to be pulled into the menu. Here is my query in layouts/index.js: export const query = graphql`

Update ACF fields inside layout via WP API

喜欢而已 提交于 2021-02-07 10:23:59
问题 I am trying to update a custom field via the WordPress API. The custom field is within an Advanced Custom Fields repeating layout and I cannot figure out how to update it. I have authentication set up and can update a post status, but I'm not having any luck in updating the ACF data. Using Postman : Page status can be updated with http://localhost:9000/wp-json/wp/v2/pages/4564/?status=public . Is there a similar value which can be used to update the ACF field or a way to update by passing

Update ACF fields inside layout via WP API

会有一股神秘感。 提交于 2021-02-07 10:22:37
问题 I am trying to update a custom field via the WordPress API. The custom field is within an Advanced Custom Fields repeating layout and I cannot figure out how to update it. I have authentication set up and can update a post status, but I'm not having any luck in updating the ACF data. Using Postman : Page status can be updated with http://localhost:9000/wp-json/wp/v2/pages/4564/?status=public . Is there a similar value which can be used to update the ACF field or a way to update by passing

I receive {“code”:“rest_forbidden”,“message”:“Sorry, you are not allowed to do that.”,“data”:{“status”:401}} when trying to retrieve a private post

人盡茶涼 提交于 2021-02-04 21:37:17
问题 Trying to retrieve a post using the REST API: http://localhost/mysite/wp-json/wp/v2/posts/605. I am authenticated as administrator and the post was published my me. I have all the administrator rights assigned. I can retrieve non-private posts but as soon as I mark them private I get an error as a response {"code":"rest_forbidden","message":"Sorry, you are not allowed to do that.","data":{"status":401}} Is there anything else I should be doing to allow retrieval of private posts ? -- Edit: I

CORS Issue Ionic 4, WordPress 5.2 and JWT Authentication

早过忘川 提交于 2021-01-29 04:03:22
问题 I am using Angular 6 and Ionic 4 with Wordpress 5.2 and JWT Authentication to access an API in wp-json. I was sure to enable CORS according to JWT Authentication and also custom CORS headers in Theme function but I am still receiving the error Access to XMLHttpRequest at 'https://oc.xxxx.com/wp-json/erp/v1/crm/contacts' from origin 'http://localhost:8100' has been blocked by CORS policy: Request header field access-control-allow-origin is not allowed by Access-Control-Allow-Headers in

Wordpress REST API + Swift

*爱你&永不变心* 提交于 2021-01-28 04:49:34
问题 I'm a novice developer trying to write a simple app that presents posts from a Wordpress site as a feed. I'm using the Wordpress REST API and consuming that within swift. I'm getting stuck at parsing the JSON and presenting it in swift. Detail below, but how do I code the dual identifier of 'title' + 'rendered' from the REST API? So far I've got this in swift: import SwiftUI struct Post: Codable, Identifiable { let id = UUID() var title.rendered: String var content.rendered: String } class

WooCommerce REST API GET multiple products by ID

故事扮演 提交于 2021-01-27 05:40:18
问题 I need to display all related products by eah product I have in my list. Eg, In my app I have 3 products with id 1, 2, 3 product id 1 has 5,6,7 as related, product id 2 with related 8 and 9 etc.. Now I have an array with all the related [5,6,7,8,9..] How can I get only this ones from REST API? I can call by single ID like that site.com/wp-json/wc/v2/products/5/ But doesn't work with multiple IDs like ../products/5/6/ or ../products/5,6/ Is this possible? 回答1: you could use parameter 'include'