0

By default when we open any author's page, WordPress displays latest posts from that author first.

What I want: If anyone opens any author's page, it will display random posts from that author.

I have searched everywhere but I couldn't find any solution.

0

use this query in themes functions.php

function ng_author_query( $query ) {
    if ( $query->is_author()
        && $query->is_main_query() ) {
            // your code to set $current_user_name here
            $query->set( 'orderby', 'rand' );
    }
}
add_action( 'pre_get_posts', 'ng_author_query' );

Let me know if you have any problem?

| improve this answer | |
  • yes, it works, thank you so much. you made my day :) – Dhaval Katrodiya Aug 16 '18 at 15:07
  • & i have one more question what should i have to do : To display random post, whenever someone opens any Tag page or any Category page – Dhaval Katrodiya Aug 16 '18 at 15:09
  • use same query change only check $query->is_tag() $query->is_category() – 1naveengiri Aug 16 '18 at 15:18
  • great, it's working, god bless you, thanks one again. – Dhaval Katrodiya Aug 16 '18 at 15:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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