如何修复 WP_Query 不列出任何文章
问题:
在你的自定义 Wordpress 插件或主题中,你有类似这样的代码
wp-query-example.php
$query = new WP_Query( );
while ( $query->have_posts() ) {
$query->the_post();
// ... 你处理文章的代码 ...
}但 $query->have_posts() 始终为 false,循环从未执行。
解决方案
WP_Query 仅在你使用适当的查询时有效。完全不使用查询不等同于列出所有文章!
这可能是你想要做的:
wp-query-fix.php
$query = new WP_Query(array('post_type' => 'post'));If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow