Будущие сообщения с ошибкой 404, когда пользователь не вошел в систему - PullRequest
0 голосов
/ 16 апреля 2020

L oop, используемый для будущих постов, приведен ниже, перечисляя обычно, но предоставляя страницу 404 по ссылке

l oop

$args = array(
            'post_type'      => 'post',
            'post_status'    => array('publish', 'future'),
            'posts_per_page' => '-1',
            'orderby'        => 'date',
            'order'          => 'ASC',
            'date_query'  => array(
                'after' => array(
                    'year'  => wp_date('Y'),
                    'month' => wp_date('m'),
                    'day'   => wp_date('d'),
                ),
                'inclusive' => true,
            ),
        );

        $lives = new WP_Query( $args );

        while ( $lives->have_posts() ) : $lives->the_post();

Просто для знания кода, Я использую приведенный ниже код внутри функций. php, чтобы сохранить красивые пермлинки

code

// Future posts permalinks fix
add_filter( 'post_link', 'future_permalink', 10, 3 );

function future_permalink( $permalink, $post, $leavename ) {
    /* for filter recursion (infinite loop) */
    static $recursing = false;

    if ( empty( $post->ID ) ) {
        return $permalink;
    }

    if ( !$recursing ) {
        if ( isset( $post->post_status ) && ( 'future' === $post->post_status ) ) {
            // set the post status to publish to get the 'publish' permalink
            $post->post_status = 'publish';
            $recursing = true;
            return get_permalink( $post, $leavename ) ;
        }
    }

    $recursing = false;
    return $permalink;
}

РЕШЕНИЕ. php:

add_filter( 'the_posts', 'show_future_posts' );

function show_future_posts( $posts ) {
   global $wp_query, $wpdb;

   if ( is_single() && $wp_query->post_count == 0 ) {
      $posts = $wpdb->get_results( $wp_query->request );
   }

   return $posts;
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...