Title: Curl::format_get
Published: March 29, 2023
Last modified: November 8, 2023

---

# Curl::format_get( string $url, array|object $data ): string

## In this article

 * [Parameters](https://developer.wordpress.org/reference/classes/wporg-requests-transport-curl/format_get/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/wporg-requests-transport-curl/format_get/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wporg-requests-transport-curl/format_get/?output_format=md#source)

This function’s access is marked private. This means it is not intended for use 
by plugin or theme developers, only by core. It is listed here for completeness.

Format a URL given GET data

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wporg-requests-transport-curl/format_get/?output_format=md#parameters)󠁿

 `$url`stringrequired

Original URL.

`$data`array|objectrequired

Data to build query using, see [https://www.php.net/http_build_query](https://www.php.net/http_build_query/)

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wporg-requests-transport-curl/format_get/?output_format=md#return)󠁿

 string URL with data

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wporg-requests-transport-curl/format_get/?output_format=md#source)󠁿

    ```php
     * @param array|object $data Data to build query using, see https://www.php.net/http_build_query
     * @return string URL with data
     */
    private static function format_get($url, $data) {
    	if (!empty($data)) {
    		$query     = '';
    		$url_parts = parse_url($url);
    		if (empty($url_parts['query'])) {
    			$url_parts['query'] = '';
    		} else {
    			$query = $url_parts['query'];
    		}

    		$query .= '&' . http_build_query($data, '', '&');
    		$query  = trim($query, '&');

    		if (empty($url_parts['query'])) {
    			$url .= '?' . $query;
    		} else {
    			$url = str_replace($url_parts['query'], $query, $url);
    		}
    	}
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/requests/src/transport/curl.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/Requests/src/Transport/Curl.php#L569)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/Requests/src/Transport/Curl.php#L569-L590)

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwporg-requests-transport-curl%2Fformat_get%2F)
before being able to contribute a note or feedback.