博客页面应在主循环中显示预定的帖子。我用这个代码做到了:
/**
* Show scheduled posts in main loop
*/
function fa_show_scheduled_posts( $query ) {
if( $query->is_main_query() && ! is_admin() && $query->is_home() ) {
$query->set( \'post_status\', [ \'publish\', \'future\' ] );
}
}
add_action( \'pre_get_posts\', \'fa_show_scheduled_posts\' );
但有一个不同的部分显示了带有WP\\U查询的4篇最新帖子。即使我将帖子状态更改为仅发布帖子,它也会显示预定的帖子。
Is there a way to show them in the main loop but not the WP_Query?
我的WP\\U查询代码:
<?php
$args = array(
\'showposts\' => 4,
\'post_status\' => array( \'publish\' )
);
$the_query = new WP_Query( $args );
用我的新代码更新,之后是wp\\u reset\\u postdata()
<?php
$args = array(
\'showposts\' => 4,
\'post_status\' => array( \'publish\' )
);
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) { ?>
<div class="featured-posts__wrap">
<div class="featured-posts js-featured-posts">
<?php while ( $the_query->have_posts() ) {
$the_query->the_post(); ?>
<div class="featured-posts__post" data-title="<?php the_title(); ?>">
<?php if ( has_post_thumbnail() ) { ?>
<div class="post-thumb">
<a href="<?php the_permalink(); ?>" rel="bookmark">
<?php the_post_thumbnail(\'full\'); ?>
</a>
</div>
<?php } else { ?>
<?php } ?>
</div>
<?php } ?>
</div>
</div>
<?php } ?>
<div class="featured-posts-info">
<?php the_title( \'<h2 class="featured-posts-info__title">\', \'</h2>\' ); ?>
</div>
<?php wp_reset_postdata(); ?>