Support » Plugin: WordPress REST API (Version 2) » rest api not working with WP REST API v1.2.5

  • I have tried to create a rest-api which will update post metadata based on <post-id> and <meta-value>. meta key is _yoast_wpseo_redirect.

    my API is not working as expected and I am getting json_no_route error while trying to hit it.

    Here is my code in functions.php

    function get_post_details ($params)
    {
    if(update_post_meta( $_GET[ 'id' ], '_yoast_wpseo_redirect', $_GET['value']))
    {
    $response['flag'] = 1;
    $response['data'] = 'Successfully Update';
    }
    else{
    $response['flag'] = 0;
    $response['data'] = 'Some Problem';
    }
    return $response;
    }
    // Register the rest route here.
        add_action( 'rest_api_init', function () {
            register_rest_route( 'wp/v2', '/post_meta/', array(
    
                            'methods'  => 'GET',
                            'callback' => 'get_post_details'
    
                        ) );
    
                });

    Thanks for the help !

  • The topic ‘rest api not working with WP REST API v1.2.5’ is closed to new replies.