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.


3 Answers 3


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;

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.

  • 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, 2011 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).

  • Thanks Kaiser but does not solve this problem. I already can't get a custom parameter on URL.
    – Marcomar
    Aug 1, 2011 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, 2011 at 19:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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