Support » Developing with WordPress » Get Random Author if had post in last month

  • Resolved mfalk75


    Hi, thanks in advance if anyone is able to help me with this. I am using the following code that gets a random author but only if they have at least 1 post. Is there anyway to modify this function so it only returns authors that have at least 1 post in the last month.

    function get_random_author_wpa91320($role){
        global $wpdb;
        //this will get all users with posts
        $ids = $wpdb->get_col("
            SELECT DISTINCT post_author
            FROM $wpdb->posts, $wpdb->usermeta
            WHERE post_type = 'post'
            AND post_status = 'publish'
            AND user_id = <code>post_author</code>
            AND meta_key = 'wp_capabilities'
            AND meta_value LIKE '%\"{$role}\"%'
        return $ids[rand(0,count($ids) -1)];
Viewing 16 replies (of 16 total)
Viewing 16 replies (of 16 total)
  • You must be logged in to reply to this topic.