gpt4 book ai didi

mysql - 每个作者在 wordpress 中的最新帖子

转载 作者:行者123 更新时间:2023-11-29 00:50:00 25 4
gpt4 key购买 nike

我有一个有 28 个用户的 Wordpress 站点,我想从每个用户那里获得最新的帖子(每个用户只有一个帖子)。我试过使用 DISTINCT 和 GROUP BY 的自定义 sql,但没有成功。

这是我离得最近的一次。它获取独特的帖子,但最旧的帖子而不是最新的。

function last_post_per_user() {
global $wpdb;
return $wpdb->get_results('SELECT ID FROM '.$wpdb->posts.' WHERE post_status=\'publish\' AND post_type=\'post\' AND post_author!=\'1\' GROUP BY post_author');
}

$posts = last_post_per_user();

foreach ($posts as $post) {
$post_id[] = $post->ID;
}

query_posts( array(
'post_type' => 'post',
'posts_per_page' => 10,
'post__in' => $post_id
) );

有没有人对如何解决这个问题有任何建议?

(实际上他妈的一整天都在尝试解决这个问题)

最佳答案

尝试替换这个:

query_posts( array( 
'post_type' => 'post',
'posts_per_page' => 10,
'post__in' => $post_id
) );

用这个:

query_posts( array( 
'post_type' => 'post',
'posts_per_page' => 10,
'post__in' => $post_id,
'orderby' => 'date',
'order' => 'DESC'

) );

它将显示最新的帖子。

关于mysql - 每个作者在 wordpress 中的最新帖子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8947658/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com