0

can I check if it's possible to hide some of the authors and display them selectively? For example, I would like to display Jerrell Seah (no avatar shown) into one of the main 12 who have avatars.

enter image description here

Thanks!

global $wpdb;

$authors = $wpdb->get_results("SELECT ID, user_nicename from $wpdb->users WHERE user_nicename != '' ORDER BY display_name");
$i=1;
foreach($authors as $author) {
    echo "<div class='col-md-3 individual-author'>";
    if($i<=12){
        echo "<div class='author-image-container'>";
        echo "<a href=\"".get_bloginfo('url')."/author/";
        echo $author->user_nicename;
        echo "\">";
        echo get_avatar($author->ID,200);
        echo "</a>";
        echo '</div>';
    }
    echo "<div class='author-name'>";
    echo "<a href=\"".get_bloginfo('url')."/author/";
    echo $author->user_nicename;
    echo "\">";
    the_author_meta('display_name', $author->ID);
    echo "</a>";
    echo "</div>";
    echo "</div>";
    echo ($i==12)?"<div class='clearfix horizontal-rule'><hr/></div>":"";
    $i++;
}
1
  • Hello, I've added the codes already and nope it doesn't seem to be through a static array. Commented Mar 8, 2016 at 10:02

1 Answer 1

1

If I were you, I would avoid custom SQL if there are perfectly fine WordPress functions for your needs.

Otherwise there's a risk that you might leave vulnerabilities or backdoors to your database which might lead to complete loss/corruption of data in the future.


Like any other query: the more arguments you use, the heavier it gets. Just make sure it does what you want and avoid unnecessary arguments. Learn more here -> WP_User_Query()

<?php

//Some selection of parameters (look codex for me)
$args = array(

    'role'           => 'Subscriber',
    'include'        => array( 1, 2, 3 ), //user IDs
    'exclude'        => array( 4, 5, 6 ), //user IDs
    'search'         => 'Rami', //Keyword search
    'user_login'     => 'demo-user',
    'user_nicename'  => 'Demo User',
    'user_email'     => '[email protected]',
    'user_url'       => 'www.demouserwebsite.com',
    'number'         => 5, //Count of users to get
    'orderby'        => 'post_count' //How to order them
);

$authors = new WP_User_Query( $args );

?>

If you want to change the order of single authors, Im afraid you'll need to add new user meta (int) to all authors. This would serve as order number which you can use as orderby argument.

1
  • Heya, thanks for the tip! But yea if I were to go about replacing it, how should i do it? I'm sorry am pretty much a php noob trying to figure things out. Commented Feb 24, 2016 at 17:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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