WordPress.org

Ready to get started?Download WordPress

Forums

How can i list random author from current post category? (1 post)

  1. genxer
    Member
    Posted 1 year ago #

    My code doing , listing authors of the current category. But i want this list random 6 author from current post category.

    <?php
    
    function getCurrentCatID(){
    
    global $wp_query;
    
    if(is_category() || is_single()){
    
    $cat_ID = get_query_var('cat');
    }
    
    return $cat_ID;
    
    }
    
    $current_category_ID = getCurrentCatID();
    $current_cat_id = $current_category_ID;
    $author_array = array();
    $args = array(
    'numberposts' => -1,
    'cat' => $current_cat_id,
    'orderby' => 'author',
    'order' => 'asc',
    
    );
    $cat_posts = get_posts($args);
    foreach ($cat_posts as $cat_post) :
    if (!in_array($cat_post->post_author,$author_array)) {
    $author_array[] = $cat_post->post_author;
    }
    endforeach;
    foreach ($author_array as $author) :
    $auth = get_userdata($author)->display_name;
    $auth_link = get_userdata($author)->user_login;
    $autid= get_userdata($author)->ID;
    $link = get_author_posts_url($autid);
    echo ''. get_avatar( $autid, '46' ).'';
    echo "<a class='sidebar-aut' href='$link";
    echo "'>";
    echo '<h6>'.$auth.'</h6>';
    echo "</a>";
    echo "<div class='clearfix'></div>";
    echo "<br />";
    endforeach;
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic