菜鸟笔记
提升您的技术认知

WordPress获取当日发布的文章

WordPress获取当日发布的文章

<?php
    $today = getdate();
    $args = array(
        'posts_per_page' => '20', // 篇数
        'ignore_sticky_posts' => true,
        'date_query' => array(
            array(
                'year'  => $today['year'],
                'month' => $today['mon'],
                'day'   => $today['mday'],
            ),
        ),
    );

    $query = new WP_Query( $args );
?>
<ul>
    <?php if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post();?>
        <li>
            <?php the_title( sprintf( '<a class="title" href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a>' ); ?>
        </li>
    <?php endwhile;?>
        <?php wp_reset_postdata(); ?>
    <?php else : ?>
        <li>
            暂无更新
        </li>
    <?php endif;?>
</ul>