• 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 can not able to find any solution on web! so plz help me.

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    The solution is really theme dependent, but the vast majority use the default main query as the source for posts to display, so the following should work. If you alter the main query through the “pre_get_posts” action, the author template of your theme should display the altered results.

    In the action callback, you mainly need to change the posts_per_page and orderby query vars. Change these to how many random posts to display and “rand”, respectively (by using $query->set()). All post queries go through this action, so before making changes, verify $query->is_main_query() and $query->is_author() are both true.

    I’m assuming your callback is collecting the passed WP_Query object as $query.

Viewing 1 replies (of 1 total)
  • The topic ‘Display Random Post in Author Page’ is closed to new replies.