$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>url rewriting - Prefix only some posts with a custom prefix|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

url rewriting - Prefix only some posts with a custom prefix

matteradmin8PV0评论

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.

Post a comment

comment list (0)

  1. No comments so far