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'm working on a project which involves filtering some customs posts on the front-end. I managed to create the permalinks including a custom field, but it seems that the rewrite rule matches some unwanted pages, making them not display-able on the frontend.

The code I use for rewriting :

$wp_rewrite->add_rewrite_tag('%competition%', '([^/]+)', 'competition=');
$wp_rewrite->add_rewrite_tag('%prize_category%', '([^/]+)', 'prize_category=');
$wp_rewrite->add_permastruct('competition', '/au/%prize_category%/%competition%/', false);

The problem is the following. It does what it should do for this url:


But it also matches this one:


Is there anyway I could force the second parameter %competition% to be mandatory? So the rule will apply only for URLs like:

http://example.com/au/param1/param2 not for domain.com/au/param1/ ?

Thanks, George

share|improve this question
up vote 1 down vote accepted

I've been struggling all morning to solve this and found your question when searching for the answer. I'm sure it's a little late for you now but in case anyone else stumbles across this question here's the solution I found:


$wp_rewrite->add_permastruct('competition', '/au/%prize_category%/%competition%/', false); 


$wp_rewrite->add_permastruct( 'competition', '/au/%prize_category%/%competition%/', array( 'walk_dirs' => false ) );

walk_dirs rewrites the "directories" that make up the URL structure and is set to true by default. Setting it to false ensures the rewrite is only used for the full URL specified.

share|improve this answer

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.