只需添加\'post__in\' => get_option(\'sticky_posts\')
对于您的查询,将您的查询限制为仅限于粘性帖子。所以
$getHighlights = array(
\'numberposts\' => 7,
\'post_type\' => array(\'post\',\'Event\'),
\'post__in\' => get_option(\'sticky_posts\'),
\'category_name\' => \'Highlights\'
);
应该对你有用。
编辑:这是如何合并两个数组以获得位于查询顶部的粘性帖子:
$getHighlights_sticky = get_posts( array(
\'numberposts\' => 7,
\'post_type\' => array(\'post\',\'Event\'),
\'post__in\' => get_option(\'sticky_posts\'),//it should be post__in but not posts__in
\'category_name\' => \'Highlights\'
));
$getHighlights_other = get_posts( array(
\'numberposts\' => 7 - count( $getHighlights_sticky ),
\'post_type\' => array(\'post\',\'Event\'),
\'post__not_in\' => get_option(\'sticky_posts\'),//it should be post__not_in but not posts__not_in
\'category_name\' => \'Highlights\'
));
foreach ( array_merge( $getHighlights_sticky, $getHighlights_other ) as $post ) {
setup_postdata( $post );
// your display loop
}
这将显示7个帖子,粘滞在顶部(当然,这是假设你没有超过7个粘滞,否则一切都会一团糟……)
(编辑以使用numberposts
根据OP以下评论……)