0

I want to display post by random author's id, like this :

<div class="css_class">
    <div class="author_id">
        author_name
    </div>
    <div id="post_author">
        <?php author_post(7,'rand', 'post_type', 'random_author_id'); ?>
    </div>
</div>

How I can get random authors and then display 10 post by that author? also when I refresh the page It should display another author with their posts.

my function to display post :

function author_post($total_post, $orderby, $random_author_id){
    global $post;
    $original_post = $post;
    $args = array(
        'post_type'              => 'post',
        'orderby'                => $orderby,
        'posts_per_page'         => $total_post,
        'author'                 => $random_author_id
    );
    $get_posts_query = new WP_Query( $args );
        while ( $get_posts_query->have_posts() ) : $get_posts_query->the_post()?>
  • Query for a single random post ('orderby'=>'rand'), grab the author id from that post (so you know it's a viable author), then use that author id to query your 10 posts. – jgraup Nov 7 '19 at 14:58
  • Can you show me how to do please ? – mems Nov 7 '19 at 15:13

Your Answer

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

Browse other questions tagged or ask your own question.