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.
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…
It’s a pretty simple solution – WP_Query utilizes the
name
variable for posts and custom post type posts. It utilizespagename
for pages, hence why?name=product1-faqs
is not working. Use this instead: