How would I know if my system using REST api or not?
You can find it simply Go to the network tab of the browser’s developer tools, and see if it makes any AJAX requests. If it does, and that response includes pure data, then that is an API.
You can find it simply Go to the network tab of the browser’s developer tools, and see if it makes any AJAX requests. If it does, and that response includes pure data, then that is an API.
I can’t really recreate the error. Are you sure the script is properly loaded? function get_post_details ($params) { return rest_ensure_response( ‘Hello World, this is the WordPress REST API’ ); } // Register the rest route here. add_action( ‘rest_api_init’, function () { register_rest_route( ‘post_info’, ‘post’,array( ‘methods’ => ‘GET’, ‘callback’ => ‘get_post_details’ )); }); This gave me … Read more
One option would be to create a Page dedicated to processing these GET requests. Something like http://example.com/create/?yourquerystringhere`. You can then create a page template, either page-create.php to automatically apply to that page, or a custom template you manually apply from the dropdown. That page template can contain your custom code: <?php // if any variables … Read more
You can modify the response data via the rest_prepare_{$this->post_type} filter, like so for a custom post type test_cpt (registered with hierarchical and show_in_rest set to true): add_filter( ‘rest_prepare_test_cpt’, ‘rest_prepare_test_cpt’ ); function rest_prepare_test_cpt( WP_REST_Response $response ) { $data = $response->get_data(); if ( ! empty( $data[‘parent’] ) ) { if ( ! $parent_post = get_post( $data[‘parent’] ) … Read more
I’m pretty sure you’re not using self-hosted WP, since you clearly mentioned that your site is running on wordpress.com… And if it really is hosted on WordPress.com, then you’ll have to use REST API a little bit different. Your API is available here: https://public-api.wordpress.com/wp/v2/sites/srebelo80.wordpress.com Here you can find Console – you can use it for … Read more
I found the problem. WordPress.com has two different application passwords. The one in the 2FA set up page is the wrong one and that’s the one I was setting up. To set the right one you need to go to /wp-admin/profile.php. Once I did that, this code started working. I wrote a blog post with … Read more
Use PHP’s strtotime() function to retrieve the timestamp for the date fourteen days ago, then date() to cast it into an ISO 8601-compliant string which can be passed into the after parameter. I’m using sprintf() here to insert the date just to keep things a bit cleaner and avoid a mess of concatenation. $url = … Read more
We can use the existing meta property (see docs) to add multiple meta fields (in a JSON format) when we create a post via POST method: POST: example.com/wp-json/wp/v2/posts/ Body payload: { “title”: “My title”, “content”: “My content”, “meta”: {“myfield1″:”myvalue1”, “myfield2″:”myvalue2”} } or when we want to update a post with ID 123: POST: example.com/wp-json/wp/v2/posts/123 Body … Read more
WP_REST_Controller::get_endpoint_args_for_item_schema() takes a single argument as the method for which to retrieve argument definitions for. It’s underlying mechanism – the rest_get_endpoint_args_for_schema() – only processes required attributes in the case of the CREATABLE methods. Change $this->get_endpoint_args_for_item_schema(true) to specify the method, i.e. $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ) or simply omit the argument and it will default to that value.
It seems to be accessible from: https://developer.wordpress.org/wp-json/wp/v2/wp-parser-class https://developer.wordpress.org/wp-json/wp/v2/wp-parser-method https://developer.wordpress.org/wp-json/wp/v2/wp-parser-hook https://developer.wordpress.org/wp-json/wp/v2/wp-parser-function and search with e.g. https://developer.wordpress.org/wp-json/wp/v2/wp-parser-function?search=get_post_embed but it’s probably best to generate your own with the WP Parser here: https://github.com/WordPress/phpdoc-parser This will create custom post types for wp-parser-hook wp-parser-function wp-parser-class wp-parser-method and related post meta (to e.g. store function input arguments, line numbers, class type, hook … Read more