显示wordpress中最近修改或更新的帖子列表



目前我有这个wordpress代码来显示最近修改或更新的帖子列表,问题是我有一个联系人表单插件,当有人通过表单发送消息时,它会自动显示在最近修改的帖子列表中。

任何方法只允许显示的帖子,页面和自定义的帖子类型和排除?

这是我的代码:

<?php
$today = current_time('mysql', 1);
$count = 8;
if ( $recentposts = $wpdb->get_results("SELECT ID, post_title FROM $wpdb->posts WHERE post_status = 'publish' AND post_modified_gmt < '$today' ORDER BY post_modified_gmt DESC LIMIT $count")):
?>

只需在查询中添加post_type过滤器,

应该类似于

SELECT ID, post_title 
FROM $wpdb->posts 
WHERE post_status = 'publish' 
AND post_modified_gmt < '$today' 
AND post_type  = 'post' // or if you want to query both post and page just do -> AND post_type IN ('post', 'page')
ORDER BY post_modified_gmt 
DESC 
LIMIT $count

最新更新