Retrieves parameters from the route itself.

Description Description

These are parsed from the URL using the regex.

Top ↑

Return Return

(array) Parameter map of key to value.

Top ↑

Source Source

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

	public function get_url_params() {
		return $this->params['URL'];

Top ↑

Changelog Changelog

Version Description
4.4.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by marcelo2605

    Return a custom field with featured the image html and set image size based on URL params:

    add_action( 'rest_api_init', function() {
        register_rest_field( 'post', 'featured_image', array(
            'get_callback' => 'wporg_get_rest_featured_image',
        ) );
    } );
    function wporg_get_rest_featured_image( $object, $attr, $request ) {
    	$image_size = $request->get_url_params( 'id' ) ? 'full' : 'thumbnail';
    	return get_the_post_thumbnail( $object['id'], $image_size );

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