我目前正在使用此代码,以便成功且无问题地获取我网站的最新三篇帖子:
$posts = get_posts( array( \'numberposts\' => 3 ) );
但我想切换到wp\\u查询。我尝试了一个简单的wp\\U查询调用,以显示我网站上发布的最新3篇文章:
$args = array(
\'posts_per_page\' => 3
);
$posts = new WP_Query( $args );
并使用此PHP代码提供此wp\\U查询的输出:<?php
while ($posts -> have_posts()) : $posts -> the_post();
foreach( $posts as $p ): ?>
<?php the_title(); ?><br>
<?php endforeach; endwhile; ?>
但最终失败了。而不是具有以下输出列表:First post title
Second post title
Third post title
First post titleFirst post titleFirst post titleSecond post titleSecond post titleSecond post titleThird post titleThird post titleThird post title