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

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.

Help anyone:)

share|improve this question

1 Answer 1

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 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.