﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	severity	resolution	keywords	cc
19493	post and archive pagination don't work with custom endpoints	mintindeed		"Archive pagination and post pagination are not endpoint-aware, so they break when endpoints are added to them.  

The following example code creates an endpoint, and then uses a filter to add that endpoint to various links on the rendered page:

{{{
add_action( 'init', function() {
	global $wp_rewrite;
	add_rewrite_endpoint( 'foo', EP_ALL );
	$wp_rewrite->flush_rules(false);
} );

add_filter( 'post_link', 'gist_add_endpoint_to_url', 99 );
add_filter( 'get_pagenum_link', 'gist_add_endpoint_to_url', 99 );
function gist_add_endpoint_to_url( $url_base ) {
	$endpoint = 'foo';

	$url_parts = parse_url( $url_base );

	$url = ( isset($url_parts['scheme']) && isset($url_parts['host']) ) ? $url_parts['scheme'] . '://' . $url_parts['host'] : '';

	$url .= isset($url_parts['path']) ? $url_parts['path'] : '';

	$url = user_trailingslashit( $url );

	if ( '' === get_option('permalink_structure') ) {
		$url .= isset($url_parts['query']) ? '?' . $url_parts['query'] : '';

		$url = add_query_arg( $endpoint, 'true', $url );
	} else {
		$url .= $endpoint . '/true';
		$url = user_trailingslashit( $url );
		$url .= isset($url_parts['query']) ? '?' . $url_parts['query'] : '';
	}

	$url .= isset($url_parts['fragment']) ? '#' . $url_parts['fragment'] : '';

	return $url;
}
}}}

You'll see that it works perfectly using the theme unit test, except that paginated posts produce URLs like this:
http://example.com/2008/09/layout-test/foo/true/2/ 
...which doesn't work.  The inverse -- http://example.com/2008/09/layout-test/2/foo/true/  -- also doesn't work, and produces a 404 on top of it. 

Also, the older posts / newer posts produce this format of link:
http://example.com/page/2/foo/true/
.. .which also doesn't work.

If you change gist_add_endpoint_to_url() to add a querystring param, older posts/newer posts links work fine, but post pagination still breaks:
{{{
function gist_add_endpoint_to_url( $url_base ) {
	$endpoint = 'foo';
	$url_base = add_query_arg( $endpoint, 'true', $url_base );
	return $url_base;
}
}}}

If you don't use a permalink structure at all, it works fine, since the pagination params are passed directly in the URL.

I'm not sure if the fix lies in modifying add_rewrite_endpoint() so that it creates pagination urls in wp_rewrite, or modifying the way _wp_link_page() and get_next_posts_link() work.  "	defect (bug)	new	normal	Awaiting Review	Rewrite Rules	2.1	normal		needs-patch	Ken@… wordpress@…
