I am trying to update a specific meta_key field using an API. meta_key name is _yoast_seo_redirect. it contains a redirect URL which we give in post options within wordpress.
What I am trying to achieve is, whenever someone hit the url like :
http://yoursite.com/wp-json/post_info/post?id=59&meta_value=www.google.com
it should update the post_id : 59 with meta_value : www.google.com
Write now, I am getting json error while trying to achieve this :
[
{
code: "json_no_route",
message: "No route was found matching the URL and request method"
}
]
Here is my function using which I am trying to achieve :
function get_post_details ($params)
{
$id = $_GET['id'];
$meta_value = $_GET['meta_value'];
if(update_post_meta( $id, '_yoast_wpseo_redirect', $meta_value ))
{
$post['status'] = 'Successfully Updated';
$post['flag'] = '1';
}
else
{
$post['status'] = 'Error';
$post['flag'] = '0';
}
if( empty( $post ) ){
return null;
}
return $post;
}
// Register the rest route here.
add_action( 'rest_api_init', function () {
register_rest_route( 'post_info', 'post',array(
'methods' => 'GET',
'callback' => 'get_post_details'
));
});
Any help would be appreciated. Thank You !