1

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

In functions.php i add this:

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

1 Answer 1

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';
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.