我的博客有很多作者。我可以列出所有作者。
所有作者列表:
<ul>
<?php wp_list_authors(\'exclude_admin=0&optioncount=1&show_fullname=1&hide_empty=1\'); ?>
</ul>
但我想以一种特殊的方式进行排序。例如,我当前正在查看技术类别页面,我想要一个具有这些id(3、10、12)的作者列表。我将在侧栏小部件中使用此代码。我需要一个用于选择作者id的元框。
当做
我的博客有很多作者。我可以列出所有作者。
所有作者列表:
<ul>
<?php wp_list_authors(\'exclude_admin=0&optioncount=1&show_fullname=1&hide_empty=1\'); ?>
</ul>
但我想以一种特殊的方式进行排序。例如,我当前正在查看技术类别页面,我想要一个具有这些id(3、10、12)的作者列表。我将在侧栏小部件中使用此代码。我需要一个用于选择作者id的元框。
当做
我假设您将在小部件选项中提供作者ID。作者将按其列出的顺序显示。
假设输入为->3,10,12
您可以使用以下代码按顺序显示具有该用户ID的作者:
$user_ids = "3,10,12"; //this is assuming you already have the value stored in a variable
//convert the comma separated string into an array
$user_ids_array = explode(",", $user_ids);
//display the list of users
echo \'<ul>\';
foreach( $user_ids_array as $id ):
$user = get_userdata( $id );
echo \'<li>\'.$user->ID.\' \'.$user->display_name.\'</li>\';
endforeach;
echo \'</ul>\';
您可以使用以下选项:
// prepare arguments
$args = array(
// search only for Authors role
\'role\' => \'Author\',
// order results by display_name
\'orderby\' => \'display_name\'
//add your custom meta key query here
);
// Create the WP_User_Query object
$wp_user_query = new WP_User_Query($args);
// Get the results
$authors = $wp_user_query->get_results();
// Check for results
if (!empty($authors))
{
echo \'<ul>\';
// loop trough each author
foreach ($authors as $author)
{
// get all the user\'s data
$author_info = get_userdata($author->ID);
echo \'<li>\'.$author->ID.\' \'.$author_info->first_name.\' \'.$author_info->last_name.\'</li>\';
}
echo \'</ul>\';
} else {
echo \'No authors found\';
}
有关更多参考,请参阅this.我已经创建了一个自定义帖子类型“hotel”和自定义“taxonomy”,所以当管理员创建一个新酒店并保存它时,会自动创建相关的自定义分类,但我不想在管理端的酒店编辑页面中显示自定义元框,因此我使用了WordPress功能,但什么都没有发生。我的自定义邮政编码 $Hotel_labels = array( \'name\' => _x(\'Hotels\', \'post type general name\'), \'singular_name\' => _x(\'Hote