$recent_url = add_query_arg( 'sort_by', 'recent');

//Default arguments
$args = array(
‘numberposts’ => 10,
‘offset’ => 0,
‘category’ => 0,
‘orderby’ => ‘post_date’,
‘order’ => ‘DESC’,
‘include’ => ,
‘exclude’ => 
,
‘meta_key’ => ,
‘meta_value’ =>
,
‘post_type’ => ‘post’,
‘post_status’ => ‘draft, publish, future, pending, private’,
‘suppress_filters’ => true );

Examples:

//  This would output '/client/?s=word&foo=bar'
echo add_query_arg( 'foo', 'bar' );

//  This would output '/client/?s=word&foo=bar&baz=tiny'
$arr_params = array ( 'foo' => 'bar', 'baz' => 'tiny' );
echo add_query_arg( $arr_params );

More often than not you’ll probably find yourself creating URLs using the following method within the page you’re currently on. In these cases you can use the URL you want to affect as the last parameter.

//  This would output 'http://blog.example.com/2009/04/16/?hello=world'
echo add_query_arg( 'hello', 'world', 'http://blog.example.com/2009/04/16/' );

Since get_permalink() returns a full URL, you could use that when you want to add variables to a post’s page.

//  This would output whatever the URL to post ID 9 is, with 'hello=there' appended with either ? or &, depending on what's needed
echo add_query_arg( 'hello', 'there', get_permalink(9) );

Removing values and setting via an associative array:

$query = 'http://example.com/link?foo=bar';
$new_query = add_query_arg(array('foo' => false, 'baz' => 'qux'), $query);
// result: http://example.com/link?baz=qux

Other Reference:

http://trotterway.com/538/wordpress-url-query-string

Advertisements