wp_remote_retrieve_cookie( array|WP_Error $response, string $name ): WP_Http_Cookie|string

Retrieves a single cookie by name from the raw response.

Parameters

$responsearray|WP_Errorrequired
HTTP response.
$namestringrequired
The name of the cookie to retrieve.

Return

WP_Http_Cookie|string The WP_Http_Cookie object, or empty string if the cookie is not present in the response.

Source

function wp_remote_retrieve_cookie( $response, $name ) {
	$cookies = wp_remote_retrieve_cookies( $response );

	if ( empty( $cookies ) ) {
		return '';
	}

	foreach ( $cookies as $cookie ) {
		if ( $cookie->name === $name ) {
			return $cookie;
		}
	}

	return '';
}

Changelog

VersionDescription
4.4.0Introduced.

User Contributed Notes

  1. Skip to note 2 content
    $json = wp_remote_get( 'http://localhost/wp-rest-api/wp-json/wp/v2/posts/' );
    $sess_cookie = wp_remote_retrieve_cookie($json, 'PHPSESSID');
    
    echo '<pre>';
    print_r($sess_cookie);
    echo '</pre>';

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