I'm creating a site where users work together on teams to create films. Currently, I'm setting up an edit page on the front end for team managers. I've just got a simple isset() check on a query var without a value to send the view to the new template page. So, regardless of the query var's value, if it's called in the URL it goes to the new template.

That part is working. The template is loading just fine at /team/(teamname)?manage. And all I'm trying to do is rewrite it so that it looks like /team/(teamname)/manage instead.

But my problem is that it's not working, AND every page on the front end is now redirecting to index.php. All except for index.php?team=blah&manage and other custom posts being called with ?team= .

Here's my file for custom rewrite rules:

function generate_manage_rewrite_rules() {
    global $wp_rewrite;

    $new_rules = array(
        "(team|film)/([^/]+)/manage/?$" => "index.php?".$wp_rewrite->preg_index(1)."=".$wp_rewrite->preg_index(2)."&manage" 
    $wp_rewrite->rules = $new_rules + $wp_rewrite->rules;

add_filter('rewrite_rules_array', 'generate_manage_rewrite_rules');

My .htaccess file which I haven't touched:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /sitename/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /sitename/index.php [L]

# END WordPress

And my file for setting template redirect and query vars (even though I don't think this is the problem):

function templateInclude( $template )
    if (is_single()) {

        global $wp_query;

        if( isset ( $wp_query->query_vars['manage'] ) ) {

            if ( is_manager() ) {

                $new_template = locate_template( array( '/template-team-manage.php' ) );
                if ( '' != $new_template ) {
                    return $new_template ;

    return $template;
add_action( 'template_include', 'templateInclude' );

I've also tried installing the Rewrite Analyzer plugin to try to figure things out, but it's not loading at all for me after installing.

1 Answer 1


Finally figured it out. 1) I was calling the first function at 'rewrite_rules_array' instead of 'init' which was just dumb. 2) There was still something wrong with it, but I explored another area that seems obvious now, but which I originally glossed over because it seemed to be.

https://codex.wordpress.org/Rewrite_API/add_rewrite_endpoint https://make.wordpress.org/plugins/2012/06/07/rewrite-endpoints-api/

Just make an endpoint. Wordpress already has the functionality built in to do what I was trying to do but it took me three days to search it out.

I literally replaced everything above (except .htaccess) with:

function manage_endpoint() {

    add_rewrite_endpoint( 'manage', EP_PERMALINK );

add_filter('init', 'manage_endpoint');

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.