WP_REST_Request::get_method(): string

Retrieves the HTTP method for the request.


string HTTP method.

Top ↑


File: wp-includes/rest-api/class-wp-rest-request.php. View all references

public function get_method() {
	return $this->method;

Top ↑


Version Description
4.4.0 Introduced.

Top ↑

User Contributed Notes

  1. Skip to note 1 content
    Contributed by caseymilne

    The return value (HTTP Method) is returned in full uppercase such as “POST”, “GET”, “PATCH”, “DELETE”. As an example in your API route callback you can check for the method type when you’re expecting one of several potential methods:

    if ( 'POST' === $request->get_method() ) {
      // Do POST specific processing.

    Alternatively you might use a switch to check the method such as:

    switch ( $request->method() ) {
      case 'POST':
        $this->do_post_processing( $request );
      case 'GET':
        $this->do_get_processing( $request );

    These examples are in the context of a callback from register_rest_route() which passes the $request (instance of WP_REST_Request) to the callback.

You must log in before being able to contribute a note or feedback.