WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

i have Wp blog that need to receive a custom paramter on category page for filter the posts like my rule.

For example:


How can I get the myvar from URL? I tried a lot of examples on the web, but no one works for the category page.


share|improve this question

Solved using this code.

add_filter( 'category_link','append_parameter', 10, 2 );

function append_parameter( $link, $my_parameter ) {
$my_parameter = $_GET['sort']; //get sort value       
if ( isset($my_parameter) ) { 
    $link = add_query_arg( 'sort', $my_parameter, $link );
    return $link;
share|improve this answer

You could use this:

$myvar = $_GET['myvar'];

and to make sure, u could also put this code in any page to test it:

echo $myvar;

This is simply the $GET[] function in PHP.

I hope it helps, and for more info visit this website.

share|improve this answer
Thanks Khalid, but when I use this code, the Wordpress just redirect for the same page without this parameter, I think that it does not accept. – Marcomar Jul 31 '11 at 22:52

Take a look at this Q and how to inspect the global $wp_query;. Then just get the relevant part (everything explained in my A).

share|improve this answer
Thanks Kaiser but does not solve this problem. I already can't get a custom parameter on URL. – Marcomar Aug 1 '11 at 22:50
@Marcomar When you retrieve $wp_query, then you already got every available parameter. As far as I understand your needs, your problem is that you want to add a custom parameter(/query_var) and not retrieve it. Else you're absolutely fine with playing with $wp_query - the only problem then is that you don't know how to handle php and query stuff (in this case, provide a code sample). – kaiser Aug 3 '11 at 19:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.