今天和同事在使用 WP_Query 的 post__in 参数的时候:
$like_query = new WP_Query(array(
'post_type' => array('post','event...'),
'post__in' => array(138,139),
'orderby' => 'post__in',
'posts_per_page'=> -1
) );
但是返回的结果总是超过这个...原来如此,我又正好使用了 sticky posts,置顶文章,所以,哎,调试了整整好几个小时,都把 WP 源代码翻烂了。...所以最终的代码应该是:
$like_query = new WP_Query(array(
'post_type' => array('post','event'),
'post__in' =>...array(138,139),
'orderby' => 'post__in',
'posts_per_page' => -1,
'ignore_sticky_posts' => 1
) );