WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am passing to my url some variables to display latest posts, most viewed etc.


I am wondering how to create a custom path for it instead for SEO purpose ie. http://website.com/highest-rated/

Help anyone:)

share|improve this question

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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