如何在wordpress中获得日期元值大于特定日期的帖子

时间:2016-04-18 15:47:25

标签: php wordpress

是否可以使用以下代码获取meta_key deadline大于特定日期值的所有帖子?

<?php $args = array(
    'posts_per_page'   => 5,
    'offset'           => 0,
    'category'         => '',
    'category_name'    => '',
    'orderby'          => 'date',
    'order'            => 'DESC',
    'include'          => '',
    'exclude'          => '',
    'meta_key'         => 'deadline',
    'meta_value'       => LARGER THAN 2016-04-19,
    'post_type'        => 'post',
    'post_mime_type'   => '',
    'post_parent'      => '',
    'author'       => '',
    'post_status'      => 'publish',
    'suppress_filters' => true 
);
$posts_array = get_posts( $args ); ?>

怎么做?

1 个答案:

答案 0 :(得分:1)

添加日期查询:

'meta_query' => array(
    array(
        'key' => 'deadline'
    ),
    array(
        'key' => 'the_date',
        'value' => '2016-04-19',
        'compare' => '>='
    )
),

根据需要修改它,但这应该有用。