wordpress的get_users是获取用户列表的,我们可以获取所有角色是author的用户,但是这个排序却没有基于最新发布文章时间(get_users order by author last post date)来排序用户列表的。

我们可以通过以下函数来实现:

function get_users_ordered_by_post_date($args = '') {  // Prepare arguments  if (is_string($args) && '' !== $args)  parse_str($args, $args);  $asc = (isset($args['order']) && 'ASC' === strtoupper($args['order']));  unset($args['orderby']);  unset($args['order']);    // Get ALL users  $users = get_users($args);  $post_dates = array();  if ($users) {  // For EACH user ...  foreach ($users as $user) {  $ID = $user->ID;    // ... get ALL posts (per default sorted by post_date), ...  $posts = get_posts('author='.$ID);  $post_dates[$ID] = '';    // ... then use only the first (= newest) post  if ($posts) $post_dates[$ID] = $posts[0]->post_date;  }  }    // Sort dates (according to order), ...  if (! $asc)  arsort($post_dates);    // ... then set up user array  $users = array();  foreach ($post_dates as $key => $value) {  // $user = get_userdata($key);  // $users[] = $user->ID;  $users[] = get_userdata($key);  }  return $users;  }

将get_users替换为get_users_ordered_by_post_date即可,参数还是传入一个$args。

有一点需要注意的时,如果要分页获取作者列表,需对数组进行分页。

$authors = get_users_ordered_by_post_date(   array(   'role__in' => array( 'author' )   )   );  if($authors){  $perpage = 16;  $pagess = ceil(count($authors) / $perpage);  if (!get_query_var('paged')) {  $paged = 1;  }else{  $paged = $wpdb->escape(get_query_var('paged'));  }  $offset = $perpage*($paged-1);  $authors2 = array_slice($authors,($paged-1)*$perpage,$perpage);  if($authors2){  foreach($authors2 as $author){    }    }    }

有种排序有个问题就是当用户以及文章越来越多时,数据查询的时间会越来越长,也就是可能会卡。


新软师兄 » WordPress如何基于最后发布文章的时间来排序作者用户列表
50T免费网盘资源大集合【持续更中~~~~】:点击查看

dase kand pornhan.mobi xvideo desi gay pcso 2pm result today pinoytvfriends.com where i can watch bad romeo كلام فى النيك wfporn.com قصص محارم حديثة busporn porngugu.mobi indian sexx vedios sex ka video noticieroporno.com himachal pradesh sex com
nero hentai hentaitgp.com ламия хентай www.mom xxx.com alohaporn.me sahara knite mature fucking tubepatrolporn.com bhabi sex indian girl sex gotporn.mobi xnxx family strocks ang probinsyano july 20 2022 full episode youtube pilipinoteleserye.com ano ang pambansang sasakyan ng pilipinas
احلي سكس محارم pornxporn.org نيك فلاحى multi.xnxx alohaporn.net telugu sex chart سكس قصيرات arabysexy.org نيك نقاب www assames sex com umora.info desi sexy bhabi 8teenx bukaporn.com india hot sex videos