0

Not sure if I've done something incorrectly here, but I have the following rewrite rule;

    add_rewrite_rule(
    '^product/([0-9]+)/([^/]+)/?$',
    'index.php?name=productl&id=$matches[1]',
    'top'
);

Which seems to work; so if I visit the following URL

mysite.com/product/23/product-description-goes-here

a page loads. However, because the wordpress permalinks are enabled, it then seems to be getting rewritten again (?) to be the post title. So the resulting URL in my address bar is

mysite.com/product/ 

this of course is breaking the page as the id is no longer in the URL. How can I have it maintain my original URL and not rewrite it to be the pages post title?

  • What is your rule supposed to be loading- a page? A custom post type? What is productl and what does id belong to? – Milo Jan 2 at 16:26
  • Hi Milo thanks for the response. 'product' (typo) is the name of a page I've created in wordpress. Inside the content of that page there is a shortcode which uses the id in the querystring parameter to fetch some data from an API – Alan Jan 3 at 9:41
  • I seem to have got it working now. I think all I needed to do was change ?name= to ?pagename= ! – Alan Jan 3 at 10:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.