_Post\u meta\u cb’,
\
)The
);
}); Now, whenever a request for \
When an authenticated request is issued by an API that uses the rest API to create and edit meta fields, all posts have additional endpoints available for meta. For example, \
For example, if you want to add a lightsaber color value to a post in Jedi post type id42, create a post request of \
The following is an example of generating meta fields using the WordPress HTTP API\/\/ Import the URL of meta in POST1
$url=rest_url (\
\/\/Add default authentication header (not used in production)
$headers= array(
Approval = > Basic. Base64_encode (\
);
Prepare the request body with \/ \/ meta key \/ value.
$body = array(
\
\
);
\/\/Create post request
$response = wp\u remote\u request ($url, array(
\
\
\
)The
);
\/\/If the response is not an error, the color is rolled back and the meta ID of the new meta key is obtained.
$body = wp\u remote\u retrieve\u body ($response);
If (! Is_wp_error ($body)){
$body = json_decode ($body);
$meta_id = $body->id;
Echo \
If ($meta_id){
\/\/Add meta ID at the end of URL
$url. = ‘\/’$ Meta_id;
\/\/You need to send the value this time.
$body = array(
\
);
$response = wp\u remote\u request ($url, array(
\
\
\
)The
);
\/\/If it is not an error, please send back the new color.
$body = wp\u remote\u retrieve\u body ($response);
If (! Is_wp_error ($body)){
$body = json_decode ($body);
Echo \
}The
}The
}The
You do not edit a meta field immediately after it is created. However, in order to explain the change method, edit the method and method of the SEO title and SEO description fields added by yoast’s word press SEO plug-in
I will show you how it can also be used in response to water testing. The
This will facilitate the whole discussion. The \
First, connect the \
If (\
$protected= false;
}The
Return $protection;
}, 10, 2); You can now register two fields in the post API. The
Male register\u api\u field (\
‘\u yoast\u wpseo\u metadesc’,
Sort(
‘get\u callback’= >’slug\u get\u post\u meta\u cb’,
‘update\u callback’= >’slug\u update\u post\u meta\u cb’,
\
)The
); All of this is ready, and you can now search for the ID through a get request to the meta endpoint of the post. This allows you to create a URL that sends a post request to update the value. Of course, if there is no value, you must create a new one. The following is a function that relies on registered and unprotected fields similar to the example code above. You can update or create the values of the two fields for a given post ID. Function slug_update_wp_seo_via_api ($post\u ID, $meta\u title, $meta\u DESC, $auth\u headers){
URL of meta imported \/\/post
$meta\u url=rest\u URL (\
\/\/Add default authentication header (not used in production)
$headers[\
\/\/Create a get request for all metadata
$response = wp\u remote\u request ($meta\u URL, array(
\
\
)The
);
\/\/If the response is not an error, continue
$body = wp\u remote\u retrieve\u body ($response);
If (! Is_wp_error ($body)){
\/\/Import metadata into an array.
$meta\u data = json\u decode ($body);
\/\/Set the variable of two field IDs to false
$meta_title_id=$meta_desc\u id= false;
\/\/Cycle until we find everyone
Foreach ($meta_data as $meta){
\/\/If the current meta key is a title setting variable
If (‘\u yoast\u wpseo\u Title’= $meta->key){
$meta_title_id = $meta->