How To Bulk Import wp_postmeta records in an API call?

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

Validate and Sanitize WP REST API Request using WP JSON Schema?

You’re already providing a schema, the parameters in args are their own schemas, but WordPress does not enforce this schema or perform sanitisation/validation by default. You can make WordPress enforce it though by setting the validation and sanitisation callbacks to the following: ‘sanitize_callback’ => ‘rest_sanitize_request_arg’, ‘validate_callback’ => ‘rest_validate_request_arg’, rest_validate_request_arg will look up the parameter in … Read more

`WP_REST_Controller::get_endpoint_args_for_item_schema` Does Not Set `required` Property from Schema

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.

Is there a way I can fetch the WordPress Developer Code References with an API?

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

Custom route and query

There are 3 issues with your code: The proper syntax of registering your custom REST API route, is as follows: register_rest_route( $namespace, $base_URL, $args, $override ); So: register_rest_route( ‘boss/v1’, ‘/latest-quiz-results’, array( ‘methods’ => ‘GET’, ‘callback’ => ‘get_latest_quiz_results’ ) ); Consult the reference for more information. In the get_latest_quiz_results(), $wpdb is not defined because you’re missing … Read more

How to use Python to create a Post in WordPress?

as @prathamesh patil say, you missed the authentication = your jwt token how to generate jwt token ? simple = core logic install and enable WordPress plugin: JWT Authentication for WP REST API wordpress server enable HTTP:Authorization purpose: allow to call /wp-json/jwt-auth/v1 api add JWT_AUTH_SECRET_KEY into wp-config.php call POST https://www.yourWebsite.com/wp-json/jwt-auth/v1/token with wordpress username and password, … Read more

Images are displaying as blank images

You should generate the attachment metadata such as width and height — and file path, and also thumbnails, after you created the attachment: Using wp_generate_attachment_metadata(): $attach_id = wp_insert_attachment( $attachment, $filename ); if ( $attach_id ) { require_once ABSPATH . ‘wp-admin/includes/image.php’; $metadata = wp_generate_attachment_metadata( $attach_id, $filename ); wp_update_attachment_metadata( $attach_id, $metadata ); } Using wp_maybe_generate_attachment_metadata(): $attach_id = … Read more

Return ‘X-WP-Total’ from headers in response

Ideally, you can access those headers with response.header, but not all headers are available publicly unless exposed manually. In your case, to access X-WP-Total by the client, you need to set the Access-Control-Expose-Headers header on your server: Access-Control-Expose-Headers: X-WP-Total

How to add a rest field to post tags?

OK finally found the solution. After looking in wp_term_taxonomy table, I noticed that taxonomy column describes the taxonomy term for tags – which is actually post_tag, not just ‘tag’. So, this works: add_filter(‘rest_prepare_post_tag’, ‘wp_api_encode_yoast’, 10, 3); Hopefully someone will be helped by this.