這段代碼根據請求返回的是按ID排序的數據,而不是作者,所以我試圖想出另一種方法來處理它。get_posts orderby ='author'not working,looking for a alternative
$args = array('posts_per_page' => '-1','order' => 'ASC', 'orderby' => 'author');
$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;
$nicename = get_userdata($author)->user_nicename;
$option = '<option value="/author/'.$nicename.'">';
$option .= $auth;
$option .= '</option>';
echo $option;
endforeach;
有沒有一種方法可以使用usermeta = user_lastname通過姓氏進行搜索和排序?或者有關如何讓這個簡單的代碼工作的任何想法。
嘗試使用author_name而不是作者? – Howli
不,''orderby'=>'author'是正確的參數'。 – AndyWarren