我试图创建WordPress的查询只显示今日编辑的,不包括今天发布的所有信息。我试过几个变化,但没有任何事情似乎工作:
$today = current_time('Ymd');
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => '10',
'meta_query' => array(
array(
'key' => 'modified',
'compare' => '>=',
'value' => $today,
'type' => 'NUMERIC,'
)
),
'orderby' => 'modified',
'order' => 'DESC',
'ignore_sticky_posts' => '1'
);
我不太肯定要放什么东西在key
,虽然这不是唯一的问题。
如果我得到它的权利,用“今天进行了编辑,只显示了帖子,那些今天发布排除。”
我猜你的意思是修改/编辑今天只显示旧发布的文章。
如果是这样的话,这可以帮助你:
<?php
// query args
$args = array(
'posts_per_page' => '10',
'post_type' => 'post',
'post_status' => 'publish',
'orderby' => 'modified',
'order' => 'DESC',
'ignore_sticky_posts' => '1',
'caller_get_posts' => 1
);
// query
$updated = new WP_Query($args);
// loop
while($updated->have_posts()) : $updated->the_post();
$today = current_time('Y-m-d'); // current date a.k.a. TODAY
$pub = get_the_time('Y-m-d', $updated->ID); // date when post was published
$mod = get_the_modified_time('Y-m-d', $updated->ID); // date when post was last modified
// if post NOT published today AND was modified today display:
if ( $pub !== $today && $mod === $today ) :
?>
<!-- here goes your normal wp game -->
<h1><?php the_title ?></h1>
<span><?php the_date(); ?></span>
<p><?php the_excerpt(); ?></p>
<?php endif; endwhile; ?>
它不是最好的解决办法,但你可以做的过滤器查询后,并检查当前的日期字符串是后修改的日期内,
EG
$ar = array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => '10',
'orderby' => 'modified',
'order' => 'DESC',
'ignore_sticky_posts' => '1'
);
$q = new WP_QUery( $ar );
$p = $q->get_posts();
foreach( $p as $a ) {
$c = current_time( 'Y-m-d' );
if ( strpos( $a->post_modified, $c ) !== false ) {
_e( $a->post_title .' '.$a->post_modified. ' - ' . $c. "<br>" );
}
}
#echo '<pre>', print_r($p, 1), '</pre>';
在此基础上查询select all posts either published or modified today,你可以只写这个WP_Query仅检索修改的:
$args = array(
'post_type' => 'post',
'post_status' => 'any', // we also want the drafts
'nopaging'=>true,
'date_query' => array(
'column' => 'post_modified',
'year' => $day_parsed['year'],
'month' => $day_parsed['month'],
'day' => $day_parsed['day'],
)
);
$query_day_posts = new WP_Query( $args );