我为添加了自定义筛选函数the_posts 在插件中筛选。
add_filter(\'the_posts\', \'posts_filter\');
function posts_filter() { … }
这在主循环中运行得很好,这意味着帖子会按照我在
posts_filter 作用
但我正在打电话get_posts() 在ajax请求中获取一些帖子。在那里,过滤器不起作用。query_posts() 或自定义wp_query 不要工作太多。
所以问题是:我如何才能在主循环旁获得按the_posts 滤器
最合适的回答,由SO网友:Mridul Aggarwal 整理而成
the_posts 适用于所有查询,包括主查询和自定义查询,但在使用get_posts(). 这是因为get_posts() 自动取消所有筛选器。如果要在使用get_posts, 您可以传递额外的密钥\'suppress_filters\' => false 在作为参数传递给的数组中get_posts()