gpt4 book ai didi

php - 按最新评论排序 Wordpress 帖子

转载 作者:可可西里 更新时间:2023-11-01 06:55:16 25 4
gpt4 key购买 nike

我想按最新评论对 Wordpress 帖子进行排序。据我所知,使用 WP_Query 对象这是不可能的,并且需要自定义 $wpdb 查询,我可以轻松编写它。但是,我不知道如何设置循环以运行此对象。

有人能帮忙吗?

最佳答案

赋值

select wp_posts.*, max(comment_date) as max_comment_date
from $wpdb->posts wp_posts
right join $wpdb->comments
on id = comment_post_id
group by ID
order by max_comment_date desc
limit 10

一些变量 $query。您可以摆弄 10 或查询本身。 (我不是 SQL 优化专家。)那么您的代码将类似于

<?php
$results = $wpdb->get_results($query) or die('!');
foreach ($results as $result):
?>
[insert template here]
<?php endforeach ?>

此模式更深入地介绍了 by the Codex .

关于php - 按最新评论排序 Wordpress 帖子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/698438/

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