我正在尝试检查我的帖子是否有内容,在循环中。目前,我在循环中添加了一个条件:
if ( $post->post_content ) 并将参数放入
wp query ('posts_per_page' => 8).我认为它可以工作,但实际上,WP query找到最后的8 posts,并检查那些8 lasts的内容。因此,它呈现2或3帖子。
我想要的是一种方式来显示最后一个有内容的8帖子。
明白我的意思了吗?
我真的很感谢您的帮助:)
诚挚的问候。
发布于 2013-05-06 17:23:08
这对于标准的WP查询是不可能的,在调用WP_Query之前,您必须利用posts_where的使用。
function filter_where($where = ''){
return $where .= "AND trim(coalesce(post_content, '')) <>''";
}在上面的例子中,我们只选择post_content列不为空的帖子。
然后添加过滤器。
add_filter('posts_where', 'filter_where');现在执行查询。
$query = new WP_Query(array('post_type' => 'post', 'posts_per_page' => 8));然后在完成后,从查询中删除过滤器,这样它就不会干扰。
remove_filter('posts_where', 'filter_where');https://stackoverflow.com/questions/16395115
复制相似问题