Php WordPress-使用自定义元显示所有用户,不包括某些用户ID
我试图在页面上显示所有用户的列表。它需要显示他们的姓名、电子邮件地址、网站URL和几个自定义作者元字段 我从以下查询开始:Php WordPress-使用自定义元显示所有用户,不包括某些用户ID,php,wordpress,Php,Wordpress,我试图在页面上显示所有用户的列表。它需要显示他们的姓名、电子邮件地址、网站URL和几个自定义作者元字段 我从以下查询开始: <?php //displays all users with their avatar and their posts (titles) $blogusers = get_users_of_blog(); if ($blogusers) { foreach ($blogusers as $bloguser) { $user = get_userdata(
<?php
//displays all users with their avatar and their posts (titles)
$blogusers = get_users_of_blog();
if ($blogusers) {
foreach ($blogusers as $bloguser) {
$user = get_userdata($bloguser->user_id);
echo get_avatar( $user->ID, 46 );
echo '<div><p>User ID ' . $user->ID . ' '
. $user->user_firstname . ' '
. $user->user_lastname . ' '
. $user->user_url . ' '
. $user->user_description
. '</p></div>';
$args=array(
'author' => $user->ID,
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => -1,
'caller_get_posts'=> 1
);
}
}
?>
这将显示基本的用户信息,但没有自定义的作者元字段。我将其调整为:
<?php
//displays all users with their avatar and their posts (titles)
$blogusers = get_users_of_blog();
if ($blogusers) {
foreach ($blogusers as $bloguser) {
$user = get_userdata($bloguser->user_id);
echo get_avatar( $user->ID, 46 );
echo '<div><p>User ID ' . $user->ID . ' '
. $user->user_firstname . ' '
. $user->user_lastname . ' '
. $user->user_url . ' '
. $user->user_description
. '</p>'; ?>
<?php the_author_meta('position', $user);?>
<?php the_author_meta('telephone');?>
<?php the_author_meta('linkedin');?>
<?php the_author_meta('vcard');?>
<?php echo '</div>';?><?php
$args=array(
'author' => $user->ID,
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => -1,
'caller_get_posts'=> 1
);
}
}
?>
这适用于第一个用户,但对于第二个用户以后的用户,它会显示第一个用户的自定义作者元数据
我花了一个小时试图找出如何进一步修改它以显示每个用户自己的自定义作者元数据,但我无法让它工作
如何修改
此外,我需要能够排除某些用户ID-我尝试添加“排除”并输入我想要排除的ID,但没有成功
请帮助作者($key)将始终检索有关作者的元信息。如果你想从任何用户那里得到meta,你需要使用get\u user\u meta($user\u id,$key,$single)
并使用$user->ID
作为ID
您可以在。的作者元($key)中找到更多信息
将始终检索有关作者的元信息。如果你想从任何用户那里得到meta,你需要使用get\u user\u meta($user\u id,$key,$single)
并使用$user->ID
作为ID
您可以在。中找到更多信息,要使用
函数获取特定用户的元,您需要传递用户id,即
php the_author_meta('telephone' 25); // will get the telephone field's value of user with id 25
所以在你的代码中你可以使用
<?php the_author_meta('position', $user->ID);?><?php the_author_meta('telephone', $user->ID);?><?php the_author_meta('linkedin', $user->ID);?><?php the_author_meta('vcard', $user->ID);?>
引用:函数已被弃用,更多信息。要使用作者元()函数获取特定用户的元,您需要传递用户id,即
php the_author_meta('telephone' 25); // will get the telephone field's value of user with id 25
所以在你的代码中你可以使用
<?php the_author_meta('position', $user->ID);?><?php the_author_meta('telephone', $user->ID);?><?php the_author_meta('linkedin', $user->ID);?><?php the_author_meta('vcard', $user->ID);?>
引用:函数已被弃用,更多信息请参见。尝试一下
echo get_the_author_meta('address', $user->ID);
查看URL
试试看
echo get_the_author_meta('address', $user->ID);
查看URL