Index: wp-includes/rewrite.php
===================================================================
--- wp-includes/rewrite.php	(revision 21049)
+++ wp-includes/rewrite.php	(working copy)
@@ -243,10 +243,11 @@
  *
  * @param string $name Name of the endpoint.
  * @param int $places Endpoint mask describing the places the endpoint should be added.
+ * @param string $query_var Name of the corresponding query variable. Defaults to $name.
  */
-function add_rewrite_endpoint( $name, $places ) {
+function add_rewrite_endpoint( $name, $places, $query_var = null ) {
 	global $wp_rewrite;
-	$wp_rewrite->add_endpoint( $name, $places );
+	$wp_rewrite->add_endpoint( $name, $places, $query_var );
 }
 
 /**
@@ -1246,7 +1247,7 @@
 				//match everything after the endpoint name, but allow for nothing to appear there
 				$epmatch = $endpoint[1] . '(/(.*))?/?$';
 				//this will be appended on to the rest of the query for each dir
-				$epquery = '&' . $endpoint[1] . '=';
+				$epquery = '&' . $endpoint[2] . '=';
 				$ep_query_append[$epmatch] = array ( $endpoint[0], $epquery );
 			}
 		}
@@ -1863,11 +1864,14 @@
 	 *
 	 * @param string $name Name of the endpoint.
 	 * @param int $places Endpoint mask describing the places the endpoint should be added.
+	 * @param string $query_var Name of the corresponding query variable. Defaults to $name.
 	 */
-	function add_endpoint($name, $places) {
+	function add_endpoint( $name, $places, $query_var = null ) {
 		global $wp;
-		$this->endpoints[] = array ( $places, $name );
-		$wp->add_query_var($name);
+		if ( empty( $query_var ) )
+			$query_var = $name;
+		$this->endpoints[] = array ( $places, $name, $query_var );
+		$wp->add_query_var( $query_var );
 	}
 
 	/**
