到目前为止,我有以下疑问:
$user_args = array(
\'role\' => \'frontend_vendor\',
\'orderby\' => \'display_name\',
\'order\' => \'ASC\',
\'number\' => $no,
\'offset\' => $offset
);
$user_query = new WP_User_Query( $user_args );
现在我要做的是获取所有只有帖子的用户,我有一个示例查询。我该如何使用
wp_query()
?
SELECT users.id, posts.id
FROM wp_users
RIGHT JOIN wp_posts
ON wp_users.id = wp_posts.user_id
WHERE wp_posts.post_type = \'downloads\'
AND wp_users.role = \'frontend_vendor\'
ORDER BY display_name
ASC
LIMT 8
OFFEST 0
如果用户没有帖子,则不应选择他。
最合适的回答,由SO网友:kenn 整理而成
将此添加到您的参数中\'query_id\' => \'authors_with_posts\',
$user_args = array(
\'role\' => \'frontend_vendor\',
\'orderby\' => \'display_name\',
\'query_id\' => \'authors_with_posts\',
\'order\' => \'ASC\',
\'number\' => $no,
\'offset\' => $offset
);
SO网友:jas
以下是一些可能的选项:
codex link
订单(&A);Orderby参数我们可以添加post\\u count,否则wp\\u查询引用中不存在诸如“posts\\u per\\u author”之类的参数
请在查询中包括orderby
\'orderby\' => \'post_count\'
FROM wp_users INNER JOIN wp_usermeta ON ( wp_users.ID = wp_usermeta.user_id ) LEFT OUTER JOIN (
SELECT post_author, COUNT(*) as post_count
FROM wp_posts
WHERE post_type = \'post\' AND (post_status = \'publish\' OR post_status = \'private\')
GROUP BY post_author
) p ON (wp_users.ID = p.post_author)
根据要求在代码中使用计数。
Get Authors or users
<?php $list = wp_list_authors(\'show_fullname=1&optioncount=1&orderby=post_count&order=DESC&number=3\'); ?>
<?php echo"<pre>"; print_r($list); echo"</pre>"; ?>
“optioncount”在这种情况下会有所帮助。
如需直接查询,请参阅以下帖子:
Get users with atleast one post
谢谢