Hook before posting via JSON REST API
json_prepare_post should be rest_prepare_post or rest_prepare_{post_type}
json_prepare_post should be rest_prepare_post or rest_prepare_{post_type}
You are using name in your terms. In default, try to use the existing term id ( in your case, cat ID and tag ID ). If you see https://plugins.trac.wordpress.org/browser/rest-api/trunk/lib/endpoints/class-wp-rest-posts-controller.php#L918 they will handle your term with sanitize them into non-negative integer using absint. I hope this help. Here example code to hook rest_insert_{$this->post_type} to create … Read more
Hopefully someone will extend on my answer…. The critical part of the rest API that is already in core is the registration and routing of endpoints which should look like (taken from http://v2.wp-api.org/extending/adding/) `/** * Grab latest post title by an author! * * @param array $data Options for the function. * @return string|null Post … Read more
The curl_init function accepts an url and what you are passing there looks like a command line call. Please check this link for an example of passing username and password through php curl functionality. Basically you have to use just http://localhost/wp-json/wc/v1/products in curl_init and set username using curl_setopt function with CURLOPT_USERPWD parameter. Example: $ch = … Read more
Solution A – Prepare User Response You can filter the response for a user to include any property you want with rest_prepare_user. add_filter( ‘rest_prepare_user’, function( $response, $user, $request ) { $response->data[ ‘first_name’ ] = get_user_meta( $user->ID, ‘first_name’, true ); $response->data[ ‘last_name’ ] = get_user_meta( $user->ID, ‘last_name’, true ); return $response; }, 10, 3 ); Solution … Read more
I found a better workaround using the same filter suggested by @ben-casey in his answer. Firstly I registered throuhg register_rest_field all the custom fields of all the user types I have in the database. Then in rest_prepare_user, insted adding the wanted fields, I removed the unwanted ones. In this way I can still use the … Read more
I don’t know if you still need this, but maybe someone else will. WooCommerce already has a REST API that’s very flexible. For your request you can simply create a API Key and use it to interogate the whole list of products. Since newest products beeing added with higher ID’s they should see the latest … Read more
Advanced custom fields uses get_field() function to retrieve the fields. So, all you have to do is to retrieve them by using: $field = get_field(‘field_name’, $post->ID, ‘format_value’); for each of your fields in the loop. You can read this page for more information. Questions about plugins are off-topic here, That’s why your question haven’t receive … Read more
My approach would be, to declare the function in functions.php and then call it whenever you need. Since you are trying to use superglobals, you can access them anywhere. Move the code from your page-foobar.php to your theme’s functions.php, and use this whenever you need to access it: ipAddress(); So, in your REST function you … Read more
WordPress REST API has nothing directly to do with the theme, REST API is in the WordPress core, and any plugin and theme can be made to support it. Normal WordPress themes don’t use REST API: it is relatively new part of the WordPress, and so far, very few themes are made to use REST … Read more