Php Wordpress在特定日期后获取帖子SQL查询问题

Php Wordpress在特定日期后获取帖子SQL查询问题,php,sql,wordpress,Php,Sql,Wordpress,所以我现在有一种获取帖子的方式: <?php $args2 = array('post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_parent' => $post->I

所以我现在有一种获取帖子的方式:

<?php 
            $args2 = array('post_type' => 'attachment', 
                           'numberposts' => -1, 
                           'post_status' => null,
                           'post_parent' => $post->ID,
                           'order' => 'ASC');  
            ?>

            <?php $attachments2 = get_posts( $args2 );   ?> 

            <?php

            if ($attachments2) { ?> ...do stuff...

…做事。。。
但我需要做的只是收集2012年3月1日之后发布的帖子

所以我不知道怎么做-我被告知要做一个SQL语句,但不知道从哪里开始

你们会怎么做


编辑:

以下是目前的整个功能:

<?php 
            $args2 = array('post_type' => 'attachment', 
                           'numberposts' => -1, 
                           'post_status' => null,
                           'post_parent' => $post->ID,
                           'order' => 'ASC');  
            ?>

            <?php $attachments2 = get_posts( $args2 );   ?> 

            <?php

            if ($attachments2) { ?>

                <h1 style='float:left'>Photos from the session</h1>

                 <?php foreach ( $attachments2 as $attachment ) {  ?>

                 <?php if( $attachment->ID != $post_thumbnail_id){ ?>

                 <div style="width:100%; height:auto;">

                 <div style="float:left; width: auto; height:auto;">

                    <?php echo wp_get_attachment_image( $attachment->ID, 'full' ); ?>

                    <div style="width:auto; height:49px; background-color:#FFF; display:block; width:100%; float:left; margin-bottom:15px;"><div class="floatiefooterright"></div></div>

                 </div>

                     <?php $desc = apply_filters( 'the_content', $attachment->post_content );

                         if($desc != ''){ ?>

                             <div style="width:auto; height:auto; margin:10px; display:block; float:left;">

                             <hr class="contentseperator" />

                                <?php if($desc != ''){ ?>

                                    <em><?php echo $desc ?></em>

                                <?php } ?> 

                             </div>

                         <?php } ?>

          </div>

                 <?php }; //end of the "if not featured image"?>

                 <?php }?>

           <?php }?>

会议照片

您应该使用过滤器来完成此操作

function after_february($where = '') {
    global $wpdb;
    $where .= $wpdb->prepare(" AND post_date > %s", "2012-03-01");
    return $where;
}

add_filter('posts_where', 'after_february');
$my_posts = get_posts(array('suppress_filters' => false));
remove_filter('posts_where', 'last_thirty_days');

不要忘记在自定义查询后删除筛选器。

正确,要完全执行您想要的操作,您不能使用。相反,您可以使用

下面是一个简单的示例,让您开始学习:

<?php

// Args
$args = array('post_type' => 'attachment', 
              'numberposts' => -1, 
              'post_status' => null,
              'post_parent' => $post->ID,
              'order' => 'ASC');


// The Query
add_filter( 'posts_where', 'filter_where' );
$query = new WP_Query( $args );
remove_filter( 'posts_where', 'filter_where' );

// The Loop
while ( $the_query->have_posts() ) { 
    $the_query->the_post();
    // do stuff with the post here
}

// Reset Post Data
wp_reset_postdata();

function filter_where($where = '') {
    $where .= " AND post_date >= '2012-03-01'";
    return $where;
}

好的,这看起来不错-现在我该怎么处理我前面提到的$attachments,还有什么不可以…你可以将你的内容输出到上面写着
//在这里处理文章的地方
$the_query->the_post()
使用函数设置全局post信息。现在您可以使用下面的函数和相关函数。您可以使用获取帖子ID,因此我在帖子中添加了一个部分,显示函数如何生成HTML。。。你介意我再深入一点吗?传奇