WP REST API – Retrieve content from page
To retrieve a page by slug, just use /wp-json/wp/v2/pages/?slug=your-page-name-here, with “your-page-name-here” obviously being the slug of your page.
To retrieve a page by slug, just use /wp-json/wp/v2/pages/?slug=your-page-name-here, with “your-page-name-here” obviously being the slug of your page.
After a lot of searching and banging my head everywhere I have successfully implemented to add WooCommerce products through Rest API. Here is my complete working code for reference :- $api_response = wp_remote_get(‘www.myapi.com’); $body = wp_remote_retrieve_body($api_response); /****** API not ready yet…working on it *******/ $data = [ ‘type’ => ‘variable’, ‘description’ => ‘Trying it out … Read more
Add a page number query to your request URL, and continue querying next page numbers until you get an empty result: <your_wordpress_install_base_url>/wp-json/wp/v2/media/?per_page=100&page=2 Mark’s suggestion to consider requesting less than 100 per page may be a good one. So for example you may want to do your query this way: <your_wordpress_install_base_url>/wp-json/wp/v2/media/?per_page=25&page=3 Note also that (for me … Read more
See if your url is correct. Example: website.com/wp-json/wp/v2/posts/?categories=3&per_page=50
This code will add categories_names field to wp rest api response: function wpse_287931_register_categories_names_field() { register_rest_field( ‘project’, ‘categories_names’, array( ‘get_callback’ => ‘wpse_287931_get_categories_names’, ‘update_callback’ => null, ‘schema’ => null, ) ); } add_action( ‘rest_api_init’, ‘wpse_287931_register_categories_names_field’ ); function wpse_287931_get_categories_names( $object, $field_name, $request ) { $formatted_categories = array(); $categories = get_the_category( $object[‘id’] ); foreach ($categories as $category) { $formatted_categories[] … Read more
In version 1.1 of the JSON REST API custom post type endpoints have to be registered manually. See: http://wp-api.org/guides/extending.html#registering-your-endpoints In version 2.0 we register endpoints for any custom post types registered with the show_in_rest property set to true. Documentation on how to do this: http://v2.wp-api.org/extending/custom-content-types/#registering-a-custom-post-type-with-rest-api-support
The issue was my staging and dev were using one minor version difference of the WP API plugin which Im assuming made a destructive change.
You can use the filter hook ‘rest_index’ : add_filter(‘rest_index’, function ($response) { $data = $response->get_data(); $data[‘namespaces’] = []; $data[‘routes’] = []; return $data; }, 9999, 1); It is possible to remove your route from $data[‘namespaces’] and $data[‘routes’]
This is how I did it, but I feel it could be better. For one thing, this results in HTTP 500… 403 would be preferable add_filter( ‘json_authentication_errors’, function( $authenticated ) { if( !$authenticated ) { return new WP_Error(‘Access Denied’); } }, 99 ); (I understand this’ll work for Basic Auth too)
You will need to add custom query vars: add_filter(‘rest_query_vars’, ‘wpse225850_add_rest_query_vars’); function wpse225850_add_rest_query_vars($query_vars) { $query_vars = array_merge( $query_vars, array(‘meta_key’, ‘meta_value’, ‘meta_compare’) ); return $query_vars; } Now, get your posts at example.com/wp-json/wp/v2/posts?filter[meta_key]=property_featured&filter[meta_value]=1. You can follow this ticket for more info.