Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

For example:

http://mysite.com/category/teste?myvar=ABC

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.

Thanks!

share|improve this question
add comment

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;
}
share|improve this answer
add comment

You could use this:

<?php
$myvar = $_GET['myvar'];
?>

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

<?php
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
add comment

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
add comment

Your Answer

 
discard

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.