Friday, September 30, 2022
HomeWordPress Developmentphp - Delete row from desk utilizing customized endpoint through API

php – Delete row from desk utilizing customized endpoint through API


I want to delete a row from a desk within the database utilizing a customized endpoint through the API. Utilizing an instance within the WordPress REST API Handbook, I put collectively the next code and positioned it in my features.php file:

    perform delete_custom_row( $id ) {
    world $wpdb;                           

    return $wpdb->delete(
        'xyz_custom_table',         
        ['id' => $id],                  
        ['%d'],                         
    );
} 

    add_action( 'rest_api_init', perform () {
        register_rest_route( 'lic-api/v1', '/deletecustomrow/(?P<id>d+)', array(
        'strategies' => 'POST',
        'callback' => 'delete_custom_row'
        ) );
    } );

I do know that I’ve a row within the desk with a column ‘id’ of three. So when I attempt to run the code utilizing the endpoint URL of:

/wp-json/lic-api/v1/deletecustomrow/3

The row just isn’t deleted and I get the next error code:

{"code":"rest_no_route","message":"No route was discovered matching the URL and request methodology.","knowledge":{"standing":404}}

Any assist could be tremendously appreciated.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments