WP_REST_Request::get_params(): array

Retrieves merged parameters from the request.

Description

The equivalent of get_param(), but returns all parameters for the request.
Handles merging all the available values into a single array.

Return

array Map of key to value.

Source

public function get_params() {
	$order = $this->get_parameter_order();
	$order = array_reverse( $order, true );

	$params = array();
	foreach ( $order as $type ) {
		/*
		 * array_merge() / the "+" operator will mess up
		 * numeric keys, so instead do a manual foreach.
		 */
		foreach ( (array) $this->params[ $type ] as $key => $value ) {
			$params[ $key ] = $value;
		}
	}

	return $params;
}

Changelog

VersionDescription
4.4.0Introduced.

User Contributed Notes

  1. Skip to note 2 content

    Example Usage: Get an array of the merged parameters from the request

    Example URL:
    https://developer.wordpress.org/?first_name=John&last_name=Doe&age=15&country=Nigeria

    Inside the REST API endpoint’s callback:

    $params = $request->get_params();
    var_dump( $params );

    Output:
    array (size=4)
    'first_name' => string 'John' (length=4)
    'last_name' => string 'Doe' (length=3)
    'age' => string '15' (length=2)
    'country' => string 'Nigeria' (length=7)

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