您将要使用WP_Query
, along with the data parameters
e、 g.年份:
$years = array( 2015,2014,2013,2012 );
echo \'<table>\';
foreach ( $years as $year ) {
$q = new WP_Query( array(
\'year\' => $year,
\'fields\' => \'ids\'
) );
echo \'<tr><td>\'.$year.\'</td><td>\'. $q->found_posts.\'</td></tr>\';
}
echo \'</table>\';
注意,我指定只获取post ID,这是为了降低查询成本。这样做还意味着您可以更好地利用缓存插件