Title: _http_build_query
Published: April 25, 2014
Last modified: August 20, 2026

---

# _http_build_query( array|object $data, string $prefix = null, string $sep = null, string $key = ”, bool $urlencode = true ): string

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/_http_build_query/?output_format=md#description)
    - [See also](https://developer.wordpress.org/reference/functions/_http_build_query/?output_format=md#see-also)
 * [Parameters](https://developer.wordpress.org/reference/functions/_http_build_query/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/_http_build_query/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/_http_build_query/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/_http_build_query/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/_http_build_query/?output_format=md#changelog)

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.

From php.net (modified by Mark Jaquith to behave like the native PHP5 function).

## 󠀁[Description](https://developer.wordpress.org/reference/functions/_http_build_query/?output_format=md#description)󠁿

### 󠀁[See also](https://developer.wordpress.org/reference/functions/_http_build_query/?output_format=md#see-also)󠁿

 * [https://www.php.net/manual/en/function.http-build-query.php](https://www.php.net/manual/en/function.http-build-query.php/)

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/_http_build_query/?output_format=md#parameters)󠁿

 `$data`array|objectrequired

An array or object of data. Converted to array.

`$prefix`stringoptional

Numeric index. If set, start parameter numbering with it.

Default:`null`

`$sep`stringoptional

Argument separator; defaults to `'arg_separator.output'`.

Default:`null`

`$key`stringoptional

Used to prefix key name.

Default:`''`

`$urlencode`booloptional

Whether to use urlencode() in the result.

Default:`true`

## 󠀁[Return](https://developer.wordpress.org/reference/functions/_http_build_query/?output_format=md#return)󠁿

 string The query string.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/_http_build_query/?output_format=md#source)󠁿

    ```php
    function _http_build_query( $data, $prefix = null, $sep = null, $key = '', $urlencode = true ) {
    	$ret = array();

    	foreach ( (array) $data as $k => $v ) {
    		if ( $urlencode ) {
    			$k = urlencode( $k );
    		}

    		if ( is_int( $k ) && null !== $prefix ) {
    			$k = $prefix . $k;
    		}

    		if ( ! empty( $key ) ) {
    			$k = $key . '%5B' . $k . '%5D';
    		}

    		if ( null === $v ) {
    			continue;
    		} elseif ( false === $v ) {
    			$v = '0';
    		}

    		if ( is_array( $v ) || is_object( $v ) ) {
    			array_push( $ret, _http_build_query( $v, '', $sep, $k, $urlencode ) );
    		} elseif ( $urlencode ) {
    			array_push( $ret, $k . '=' . urlencode( $v ) );
    		} else {
    			array_push( $ret, $k . '=' . $v );
    		}
    	}

    	if ( null === $sep ) {
    		$sep = ini_get( 'arg_separator.output' );
    	}

    	return implode( $sep, $ret );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/functions.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/functions.php#L1069)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/functions.php#L1069-L1105)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/_http_build_query/?output_format=md#related)󠁿

| Uses | Description | 
| [_http_build_query()](https://developer.wordpress.org/reference/functions/_http_build_query/)`wp-includes/functions.php` |

From php.net (modified by Mark Jaquith to behave like the native PHP5 function).

  |

| Used by | Description | 
| [build_query()](https://developer.wordpress.org/reference/functions/build_query/)`wp-includes/functions.php` |

Builds a URL query based on an associative or indexed array.

  | 
| [_http_build_query()](https://developer.wordpress.org/reference/functions/_http_build_query/)`wp-includes/functions.php` |

From php.net (modified by Mark Jaquith to behave like the native PHP5 function).

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/_http_build_query/?output_format=md#changelog)󠁿

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

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2F_http_build_query%2F)
before being able to contribute a note or feedback.