Why do WordPress rewriites seem to work differently for posts vs pages?

I am creating some simple rewrites in my functions.php file in my WordPress installation:

add_rewrite_rule('product1/faqs/?', 'index.php?name=product1-faqs', 'top'); 

I’ve noticed that if you hit “product1/faqs” in the browser, it successfully displays the content of “product1-faqs” but keeps the url as product1/faqs (which is desired) but only if it is a POST.

Read More

If I try this same technique but on a PAGE, the browser URL flicks to “product1-faqs” (undesired!)

Why is that? I don’t want have to limit ourselves just to posts for the sake of rewrites working as desired…

Related posts

Leave a Reply

1 comment

  1. It’s a pretty simple solution – WP_Query utilizes the name variable for posts and custom post type posts. It utilizes pagename for pages, hence why ?name=product1-faqs is not working. Use this instead:

    add_rewrite_rule('product1/faqs/?', 'index.php?pagename=product1-faqs', 'top');