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'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:

http://example.com/au/win-a-holiday/win-a-long-weekend-at-the-rees-hotel-queenstown/

But it also matches this one:

http://example.com/au/win-a-holiday/

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

1 Answer 1

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:

Change:

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

to:

$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

 
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.