this is driving me crazy!!

Scenario is...

Custom post type let's call it "cpt_product" setup with the rewrite "products"

Trying to use the add_rewrite_rule to create a friendly URL for meta details pertaining to the product. For example, this custom post type has 3 meta fields associated with each post (mt_details, mt_inventory, and mt_availability)

Desired URL sequence is




This would allows access to a parameter on the front-end which would allow the highlight of that information.

This is the closest I've gotten just need a little help please!

function yoursite_init() {
  global $wp,$wp_rewrite;
'index.php?metahighlight=details&post_type=cpt_product&name=$matches[1]', 'top');

  // Once you get working, remove this next line

I did use this method although it didn't seem to help me... just trying to get a single one of these nice url's working.

When I access the URL:


Wordpress returns


When what I'm looking for is www.sitename.com/products/product-name/details/

Any suggestions would be greatly appreciated.

  • Thanks for the quick response @G. M. I updated the questions above to include more detail
    – Simon
    Oct 3, 2013 at 23:33
  • 2
    This is absolutely normal. You have to go to www.sitename.com/products/product-name/details/ and thanks to the rule it will be recognized just like you type www.sitename.com/index.php?metahighlight=details&post_type=cpt_product&name=product-name but showing in the browser the pretty url. But if you put in the browser the ugly url, WP will not replace it with the pretty one: if you want this you should implement the redirection by yourself. In short rewrite rules works showing pretty url and recognizing vars just like the ugly url was in the browser.
    – gmazzap
    Oct 3, 2013 at 23:43


Your Answer

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