$termscat = get_terms([
'taxonomy' => 'newscategories',
'orderby' => 'count',
'order' => 'DESC',
'hide_empty' => false
]);
我正在使用上面的代码来获取帖子数,并返回所有帖子,但是我只想按今天的日期过滤数据。
答案 0 :(得分:1)
我想你想要这样的东西。
选择count(post。ID
)作为count,rel。term_taxonomy_id
,terms.name FROM {$wpdb->base_prefix}posts
作为post INNER JOIN {$ wpdb-> base_prefix} term_relationships作为rel ON post .ID = rel。object_id
内部联接{$ wpdb-> base_prefix}术语作为rel上的术语。term_taxonomy_id
= terms.term_id WHERE post_date
类似于'$ currentDate%'和post.post_type ='$ post_type'GROUP BY rel。term_taxonomy_id
ORDER BY count DESC
答案 1 :(得分:0)
get_terms()
用来获取术语而不是帖子。
如果要获取当前日期的帖子,则可以使用下面的代码
$today = date( 'Y-m-d' );
$args = array(
'post_type' => 'vehicle',
'date_query' => array(
//set date ranges with strings!
'after' => 'today',
//allow exact matches to be returned
'inclusive' => true,
),
);
$query = new WP_Query( $args );
您可以获取有关此https://codex.wordpress.org/Class_Reference/WP_Query#Date_Parameters
的更多信息答案 2 :(得分:0)
$today['year'] = current_time('Y');
$today['mon'] = current_time('m');
$today['mday'] = current_time('d');
$args = array(
'post_type' => 'news',
'date_query' => array(
array(
'year' => $today['year'],
'month' => $today['mon'],
'day' => $today['mday'],
),
),
'tax_query' => array(
array(
'taxonomy' => $tex_name,
'field' => 'term_id',
'terms' => $term_id,
),
),
);
$query = new WP_Query( $args );
$total = $query->found_posts;