我正在将所有query\\u posts查询转换为get\\u posts,之前我做了大量关于这对性能有多糟糕的研究。我的解决方案是get\\u posts,但使用它让我感到困惑。以下是我所拥有的:
$posts = get_posts(\'showposts=-1&offest=10&post_type=any\');
foreach ($posts as $post) :
?>
<div class="box">
<a href="<?php the_permalink() ?>" rel="bookmark">
<h2><?php the_title(); ?></h2>
<?php if (has_post_thumbnail()) {
the_post_thumbnail(\'thumbnail\');
}?>
<?php the_content();?></a>
</div><?php endforeach; ?>
它可以工作,但有些参数不能工作,例如offset和“any”post类型非常模糊。$posts = get_posts(\'showposts=-1&offest=10&post_type=any\');
法典告诉我们,我们也可以使用数组:$query = new WP_Query( array( \'post_type\' => array( \'post\', \'page\', \'movie\', \'book\' ) ) );
但这是一个我不知道如何处理的常见问题。如何将动态参数获取到数组中,或者在哪里可以找到字符串格式的参数规则(如代码)?