custome route to a page with dynamic parameters wordpress

73

function custom_rewrite_rule(){
    $page_id = 318; // replace this ID with the page with the iFrame template 

    $page_data = get_post($page_id);

    if(!is_object($page_data)){
        return; // all other pages don't have to support custom deeplinks
    }

    // catches deeplinks 1 level deep, i.e.: /members/profile
    add_rewrite_rule(
        $page_data->post_name . '/([^/]+)/?$',
        'index.php?pagename=' . $page_data->post_name . '&memberspage=$matches[1]',
        'top'
    );

    // catches deeplinks 2 levels deep, i.e.: /members/profile/edit
    add_rewrite_rule(
        $page_data->post_name . '/([^/]+)/([^/]+)/?$',
        'index.php?pagename=' . $page_data->post_name . '&memberspage=$matches[1]&members_param=$matches[2]',
        'top'
    );

    // catches 3 levels deep, i.e. /members/profile/edit/confirm
    add_rewrite_rule(
        $page_data->post_name . '/([^/]+)/([^/]+)/([^/]+)/?$',
        'index.php?pagename=' . $page_data->post_name . '&memberspage=$matches[1]&members_param=$matches[2]&members_param2=$matches[3]',
        'top'
    );

}

add_action('init', custom_rewrite_rule);

Comments

Submit
0 Comments