Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness. Use https://www.php.net/manual/en/function.http-build-query.php instead.

_http_build_query() WordPress Function

The http_build_query() function in WordPress is used to build a URL query string from an array of data. This function can be used to generate a URL query string for use in a URL or to generate data for use in a POST request.

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

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


Description

Top ↑

See also


Top ↑

Parameters

$data

(array|object)(Required)An array or object of data. Converted to array.

$prefix

(string)(Optional) Numeric index. If set, start parameter numbering with it.

Default value: null

$sep

(string)(Optional) Argument separator; defaults to 'arg_separator.output'.

Default value: null

$key

(string)(Optional) Used to prefix key name.

Default value: ''

$urlencode

(bool)(Optional) Whether to use urlencode() in the result.

Default value: true


Top ↑

Return

(string) The query string.


Top ↑

Source

File: wp-includes/functions.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 );
}


Top ↑

Changelog

Changelog
VersionDescription
3.2.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More