WordPress.org

Ready to get started?Download WordPress

Forums

Display Authors Widget
Random authors (3 posts)

  1. alex27
    Member
    Posted 1 year ago #

    Would it be possible to modify the widget, so that it displays random authors? For example I don't want to display all my blog authors, only 2 or 3, but I want them to be randomly chosen so that I don't end up with the same 3 authors on every page! I'm good with php, so I should be able to code it myself, but I'd appreciate any pointers.

    http://wordpress.org/extend/plugins/display-authors-widget/

  2. Sami Keijonen
    WordPress-asiantuntija
    Plugin Author

    Posted 1 year ago #

    This plugin uses get_users function and it doesn't have random order. You can check the orderby values here.

    http://codex.wordpress.org/Function_Reference/get_users

    You can filter query like this in your custom plugin or child theme functions.php.

    add_filter( 'display_authors_widget_query', 'my_order_by_post_count' );
    
    function my_order_by_post_count( $query_args ) {
    
    	$query_args['order_by'] = 'post_count';
    
    	return $query_args;
    
    }

    Maybe you could play with offset value like this.

    add_filter( 'display_authors_widget_query', 'my_order_by_post_count' );
    
    function my_order_by_post_count( $query_args ) {
    
    $my_random = rand(0, 10);
    
    $query_args['offset'] = $my_random;
    
    return $query_args;
    }
  3. alex27
    Member
    Posted 1 year ago #

    Thank for your reply. I ended up using your plugin as a base and making many more customizations. Thanks again!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic