Skip to main content
added 1158 characters in body
Source Link
Elizabeth
  • 377
  • 2
  • 13

Update with my new code, with wp_reset_postdata() coming after everything

  <?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(); ?>

Update with my new code, with wp_reset_postdata() coming after everything

  <?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(); ?>
deleted 2 characters in body
Source Link
Elizabeth
  • 377
  • 2
  • 13

The blog page should show scheduled posts in the main loop. I've done that with this code:

/**
 * 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' );

But there's a different section that shows the 4 latest posts with a WP_Query. Even if I change the post status to only be published posts, it shows the scheduled posts.

Is there a way to show them in the main loop but not the WP_Query?

My WP_Query code:

      <?php
      $args = array(
      'showposts' => 4,
      'post_status' => array( 'published''publish' )
      );

      $the_query = new WP_Query( $args );

The blog page should show scheduled posts in the main loop. I've done that with this code:

/**
 * 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' );

But there's a different section that shows the 4 latest posts with a WP_Query. Even if I change the post status to only be published posts, it shows the scheduled posts.

Is there a way to show them in the main loop but not the WP_Query?

My WP_Query code:

      <?php
      $args = array(
      'showposts' => 4,
      'post_status' => array( 'published' )
      );

      $the_query = new WP_Query( $args );

The blog page should show scheduled posts in the main loop. I've done that with this code:

/**
 * 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' );

But there's a different section that shows the 4 latest posts with a WP_Query. Even if I change the post status to only be published posts, it shows the scheduled posts.

Is there a way to show them in the main loop but not the WP_Query?

My WP_Query code:

      <?php
      $args = array(
      'showposts' => 4,
      'post_status' => array( 'publish' )
      );

      $the_query = new WP_Query( $args );
Source Link
Elizabeth
  • 377
  • 2
  • 13

Show scheduled posts in main loop but not in WP_Query?

The blog page should show scheduled posts in the main loop. I've done that with this code:

/**
 * 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' );

But there's a different section that shows the 4 latest posts with a WP_Query. Even if I change the post status to only be published posts, it shows the scheduled posts.

Is there a way to show them in the main loop but not the WP_Query?

My WP_Query code:

      <?php
      $args = array(
      'showposts' => 4,
      'post_status' => array( 'published' )
      );

      $the_query = new WP_Query( $args );