I am finding myself using this function a lot now, and I constantly forget the function name:
add_query_arg();
It allows you to pass in some additional parameters, and a URL, and receive back the URL with the query string params added. For example:
$some_url = "http://simonwheatley.co.uk/?stuff=whatever";
$params = array( 'wp_siteurl' => "http://www.example.com" );
$some_url = add_query_arg( $params, $some_url );
This will result in a url something like this:
http://simonwheatley.co.uk/?stuff=whatever&wp_siteurl=http%3A%2F%2Fwww.example.com
Pretty cool, huh? So now you don’t need to worry about what parameters are already in the URL, you can just hand all that hassle to add_query_arg.
Update: See also remove_query_arg
.
Thanks Simon!
I am tweaking WordPress to be like a CMS and I am looking for good ways to combine WP with raw PHP in it and make it powerful and sending parameters is a great deal.
You explain how to send the params, but is there a better way to read them rather than just using $_GET[‘stuff’] integrated in the core WordPress? (I mean without using plugins)
Cheers
Cheers Simon, I too, like Lucky Shot am trying to make it look more like a regular website and less like a blog… I had achieved this in the past using Smarty but the solution wasn’t as portable and you couldn’t just switch to another theme easily at all…
I’d love to compare notes with Lucky Shot too!
Hallelujah. I’m eternally forgetting, and then searching for for this function, and I never seem to be able to find it. Thanks for posting on it.
Hi again,
I found this site http://webopius.com/content/137/using-custom-url-parameters-in-wordpress
which explains how to create a simple plugin to manage custom get queries through WordPress itself with something like this:
$wp_query->query_vars[‘myvar’]
Hope it helps!
How can i use this inside the plugin…