I have this resource: (http://codex.wordpress.org/Function_Reference/build_query), but it does not give full example.
I have this URL:
mypage/?page_id=87
and this array:
array('name' => 'me')
So, I need to add the array to the end of the URL. I know the build_query function will add the proper markup ( & ), but how do I connect the function to the URL. e.g.- How do I use the function?
build_query()
converts an array into a string to be used in an URL. You can pass an array or an object:To get the current URL you can use something like this:
Now you could use
build_query()
to append your custom array values to the URL, but you can make that easier withadd_query_arg()
:add_query_arg()
will look for existing parameters in the URL and make sure they donât get lost or interfere with the$custom
values. If there are duplicate entries in both,$custom
will overwrite existing parameters.build_query()
is used inadd_query_arg()
too, but for no obvious reasons you cannot pass an object toadd_query_arg()
like you can use it inbuild_query()
. Objects are dropped silently.