Title: Request::withData
Published: May 20, 2026

---

# Request::withData( $data ): self

## In this article

 * [Parameters](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-http-dto-request/withdata/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-http-dto-request/withdata/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-http-dto-request/withdata/?output_format=md#source)
 * [Changelog](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-http-dto-request/withdata/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-http-dto-request/withdata/?output_format=md#wp--skip-link--target)

Returns a new instance with the specified data.

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-http-dto-request/withdata/?output_format=md#parameters)󠁿

mixed> $data The request data.

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-http-dto-request/withdata/?output_format=md#return)󠁿

 self A new instance with the data.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-http-dto-request/withdata/?output_format=md#source)󠁿

    ```php
    public function withData($data): self
    {
        $new = clone $this;
        if (is_string($data)) {
            $new->body = $data;
            $new->data = null;
        } elseif (is_array($data)) {
            $new->data = $data;
            $new->body = null;
        } else {
            $new->data = null;
            $new->body = null;
        }
        return $new;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/php-ai-client/src/providers/http/dto/request.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/php-ai-client/src/Providers/Http/DTO/Request.php#L258)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/php-ai-client/src/Providers/Http/DTO/Request.php#L258-L272)

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-http-dto-request/withdata/?output_format=md#changelog)󠁿

| Version | Description | 
| [0.1.0](https://developer.wordpress.org/reference/since/0.1.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwordpress-aiclient-providers-http-dto-request%2Fwithdata%2F)
before being able to contribute a note or feedback.