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've been banging my head against a wall on this one for a while but I'm not quite sure from all the tutorials I read how to see why this isn't doing what I expect.

I have a page called shop-guide/shop-page?id=412 (for example)

and I want to change it so it it's shop-guide/shop-page/id/412/

As far as I can tell I have my code set up correctly, but when I try to navigate to the page I get a 404, and if I use the $_GET version it doesn't rewrite.

Here's my code: (in functions.php)

function wptuts_add_rewrite_rules() {  
add_rewrite_rule(  
    'shop-guide/shop-page/id/([^/]*)/',  
    'index.php?p=143&id=$matches[1]',  
    'top' 
);  
}  
add_action( 'init', 'wptuts_add_rewrite_rules' ); 
share|improve this question
add comment

2 Answers 2

Two issues -

your rewrite rule isn't formatted correctly, this:

'shop-guide/shop-page/id/([^/]*)/'

should be:

'shop-guide/shop-page/id/([^/]*)/?$'

and if shop-guide and shop-page are parent / child pages, this:

'index.php?p=143&id=$matches[1]'

should be:

'index.php?pagename=shop-guide/shop-page&id=$matches[1]'
share|improve this answer
    
Thanks so much! That fixed it for me. –  LetterAfterZ Jan 30 '13 at 0:40
add comment

I believe you first need to register your custom querystring variable. You could use add_rewrite_tag for this purpose: http://codex.wordpress.org/Rewrite_API/add_rewrite_rule

See the important note down at the bottom of the codex article

Edit:

You could also use query_vars hook to add your own custom query variables.

share|improve this answer
    
Thanks, I've added the additional call (and in rewrite analyzer plugin it's working correctly), but the page is still returning a 404 instead of the actual page. function wptuts_add_rewrite_rules() { add_rewrite_tag('%id%','([^&]+)'); add_rewrite_rule( 'shop-guide/shop-page/id/([^/]*)/', 'index.php?p=143&id=$matches[1]', 'top' ); } add_action( 'init', 'wptuts_add_rewrite_rules' ); –  LetterAfterZ Jan 30 '13 at 0:16
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.