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.
For instance, WP_Query is only for fetching standard post data. Additional data by plugins such as WC will not be fetched. To do a custom query If you would like to use a custom query, you could use WC_Product_Query Place the following in theme’s functions.php and save the javascript into a separate php file. The … Read more
Just found the solution in another question of Stack Overflow. Using the function register_meta(): register_meta(‘user’, ‘icq’, array( “type” => “string”, “show_in_rest” => true )); Now I can make a request using: { “username” : “johndoe”, “email”: “[email protected]”, “password”: “qwerty”, “meta”: { “icq”: “11223344” } } And the response are: { “id”: 49, “username”: “johndoe”, “name”: … Read more
it’s file_put_contents which saves the data then it have to be in the hook and not in the body of the plugin : function export_posts_in_json () { $args = array( ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => -1, ); $query = new WP_Query( $args ); … $data = json_encode($posts); $folder=”wp-content/themes/bootstrap/library/”; $file_name = date(‘Y-m-d’) . … Read more
You can either use the JSON API plugin, or wait for the JSON REST API project that is now running through the Google Summer of Code project. This is intended to eventually go into WordPress core, but will work as a standalone plugin for the time being.
Admin-AJAX is not optimized for JSON. If you need your answer to be in JSON, use the REST-API instead. This API generates JSON response by default. All you have to do is to register a rest route, and access the URL: add_action( ‘rest_api_init’, function () { //Path to REST route and the callback function register_rest_route( … 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
Newlines are not valid inside json strings. However you are outputting this code or otherwise checking it for sanity is somehow adding newlines into your long strings here. Check that your strings really are all one line and not broken up into multiple lines.
Your action hook should be add_action( ‘wp_ajax_cc_author_change_postauthor’, ‘cc_author_change_postauthor_callback’ ); I think because of your wrong hook, your callback function is never called. You might have got this wrong aswell. In your JS code please change your action from cc-author-change-postauthor to cc_author_change_postauthor
There are two aspects here obviously all input should be sanitized JSON is just a wrapper no different then any other type of container which is used to aggregate data for transmission. You almost never sanitize the container as usually in case of an error you will just not be able to extract the data … Read more