我不是php专家,需要一些关于wordpress作者页面自定义查询的帮助。
我使用WP_User_Query时没有问题,问题是我需要将它与$curauth
结合起来我需要做的是获得作者列表与WP_User_Query过滤与当前作者页面作为自定义字段值。
下面是得到错误的代码:// WP_User_Query arguments
$curauth = (isset($_GET['author_name'])) ? get_user_by('slug', $author_name) : get_userdata(intval($author));
$label = echo $curauth->user_login;
$args = array (
'role' => 'contibutor',
'number' => '10',
'order' => 'ASC',
'orderby' => 'display_name',
'meta_query' => array(
array(
'key' => 'user_label',
'value' => $label,
),
),
);
// The User Query
$user_query = new WP_User_Query( $args );
// The User Loop
if ( ! empty( $user_query->results ) ) {
foreach ( $user_query->results as $user ) {
// do something
}
} else {
// no users found
}
我希望这里有人能帮助解决我的问题。谢谢你 试试这个
$curauth = ( isset( $_GET['author_name'] ) ) ? get_user_by( 'slug', $author_name ) : get_userdata( intval( $author ) );
$args = array (
'role' => 'contibutor',
'number' => '10',
'order' => 'ASC',
'orderby' => 'display_name',
'meta_query' => array(
array(
'key' => 'user_label',
'value' => $curauth->user_login,
),
),
);
// The User Query
$user_query = new WP_User_Query( $args );
// The User Loop
if ( ! empty( $user_query->results ) ) {
foreach ( $user_query->results as $user ) {
// do something
}
} else {
// no users found
}
正如pieter-goosen在评论中指出的,$label = echo $curauth->user_login;
行是导致错误消息的原因。