I'm lost in the world of Wordpress rewrites and I'm hoping someone can help...
I'm creating two custom members areas from my site; users logged in as certain roles will be able to view certain posts, guests won't be able to see the posts.
There are two areas for members, let's call them gold
and silver
The gold/silver members 'dashboards' will be at or
I want to create a rewrite rule for blog posts so that if you go to you see the post with a name of
post-slug-here
(without redirecting to ). I need to keep the URL so I know which area the user is in (some posts will be viewable in both)
I've tried...
add_action( 'init', 'members_area_single_rewrites' );
function members_area_single_rewrites() {
add_rewrite_rule(
// The regex to match the incoming URL
'gold/(.+?)/?$',
// The resulting internal URL
'index.php?pagename=$matches[1]',
// Add the rule to the top of the rewrite list
'top' );
}
I am resaving in Settings -> Permalinks after every code change.
Now if I visit the URL, it finds the post, but redirects to the non-prefixed URL. What am I missing?
I am also not sure if I can add 'gold' or 'silver' as an area
query_var so that I can then do something like if (get_query_var('area') == 'gold')
which would be super helpful.