【问题标题】:Searching post by date on the wordpress在 wordpress 上按日期搜索帖子
【发布时间】:2016-08-13 09:19:47
【问题描述】:

我的计划是制作一个日期搜索表单,但我需要在搜索时查询发布日期,因为例如如果我搜索 8 月 13 日,它将不会显示任何内容,

我如何搜索帖子的发布日期

我正在使用此代码但没有任何反应我尝试阅读这篇文章https://developer.wordpress.org/reference/functions/query_posts/,我非常抱歉我是 wordpress 和 php 的新手,学习谢谢。我认为这是错误的

        <?php
        global $wp_query;
        $args = array_merge( $wp_query->query, array( 'posts_per_page' => 12, 
        'year'  => $current_year,
        'monthnum' => $current_month,
        'order'    => 'ASC' ) );
        query_posts( $args );        
        $x = 0;
        while (have_posts()) : the_post(); ?>     

这是我的普通搜索

            <?php
        global $wp_query;
        $args = array_merge( $wp_query->query, array( 'posts_per_page' => 12 ) );
        query_posts( $args );        
        $x = 0;
        while (have_posts()) : the_post(); ?>      

【问题讨论】:

    标签: php html wordpress


    【解决方案1】:

    您应该尝试以下方法:

    <?php
    $year = '1365';
    $month = '03';
    $day = '30';
    $search_date = new WP_Query( 'year=' . $year . '&monthnum=' . $month . '&day=' . $day );
    if($search_date->have_posts()) : while ($search_date->have_posts()) : $search_date->the_post();?>
       <a href="<?php the_permalink(); ?>">
             <?php the_title(); ?>
       </a>
       <br/>
    <?php endwhile; endif; ?>
    

    这将显示一个简单的标题列表,其中包含来自 1365.03.30 的帖子链接

    【讨论】:

      猜你喜欢
      • 2019-03-13
      • 1970-01-01
      • 1970-01-01
      • 2011-10-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-11
      相关资源
      最近更新 更多