WordPress add rules on Nginx doesnt works

I would like to rewrite url and pass parameters in URL (GET) on wordpress (nginx server).

In functions.php i add this:

Read More
add_action('init', 'add_my_rewrite'); 
function add_my_rewrite() 
{   
global $wp_rewrite;   
add_rewrite_tag('%jeans%','([^&]+)');   
$wp_rewrite->add_rule('catalogue/([^/]+)/','index.php?pagename=catalogue&jeans=$matches[1]','top');

$wp_rewrite->flush_rules(); 
}

Then in my php file id this:

global $wp_query;
$jeans = $wp_query->query_vars['jeans'];
echo $jeans;

But it doesnt works

Related posts

Leave a Reply

1 comment

  1. WordPress doesn’t automatically import querystring variables into $wp_query. You have to modify the WP query with code, which varies depending on what you want it to do.

    Just so we’re clear, $wp_query is the database query. The “query” string variables in the URL can be accessed via $_GET.

        echo $_GET['jeans'];
    

    (But you should check if it isset() first.)

        echo isset( $_GET['jeans'] ) ? $_GET['jeans'] : 'Not set';