WordPress:按月分组帖子?

时间:2016-03-21 18:52:17

标签: php mysql wordpress

有办法做到这一点吗?

August 2009
11 Title of the post of the 11th day of August
15 Title of other post of the 15th day of August
20 Title of another post of the 20th day of August

July 2009
4 Title of the post of the 4th day of July
7 Title of other post of the 7th day of July
15 Title of another post of the 15th day of July

我需要通过自定义元框evmeta_test_textdate

对此帖子进行分组
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$format_of_date = 'Y/m/d';
$oldest = date($format_of_date, strtotime('-30 days'));
$args=array(
  'meta_key'=> 'evmeta_test_textdate',
  'meta_value'=> $oldest,
  'meta_compare'=> '>=',
  'post_type' => 'upg',
  'post_status' => 'publish',
  'order' => 'ASC',
  'paged' => $paged,
);
$query = new WP_Query( $args );

谢谢!

1 个答案:

答案 0 :(得分:0)

Wordpress的默认行为是按发布日期和查询处理日期,格式如下:

$args = array(
    'date_query' => array(
        array(
            'year'  => 2012,
            'month' => 12,
            'day'   => 12,
        ),
    ),
);
$query = new WP_Query( $args );

为什么要按自定义元处理日期有特殊原因吗?