You could add the path via add_rewrite_endpoint
, then alter the query via the pre_get_posts
action. Here's a proof-of-concept example that alters the posts_per_page
when domain.com/highest-rated/
is requested:
// add the endpoint
function wpa85664_add_endpoint(){
add_rewrite_endpoint( 'highest-rated', EP_ALL );
}
add_action( 'init', 'wpa85664_add_endpoint' );
// check if the endpoint is in the current request
// and alter the query accordingly
function wpa85664_check_endpoint( $query ){
if( array_key_exists( 'highest-rated', $query->query_vars ) )
$query->set( 'posts_per_page', -1 );
}
add_action( 'pre_get_posts', 'wpa85664_check_endpoint' );
You could alter any relevant query vars with this method, for example a meta query to sort posts by rating.