Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 如何在wordpress的get_术语中获得今天的帖子_Mysql_Wordpress - Fatal编程技术网

Mysql 如何在wordpress的get_术语中获得今天的帖子

Mysql 如何在wordpress的get_术语中获得今天的帖子,mysql,wordpress,Mysql,Wordpress,我使用上述代码获取帖子计数,并返回所有帖子,但我只想按今天的日期筛选数据。获取用于获取条款而非帖子的条款 如果你想获得当前日期的帖子,你可以使用下面的代码 $termscat = get_terms([ 'taxonomy' => 'newscategories', 'orderby' => 'count', 'order' => 'DESC', 'hide_empty' => false ]);

我使用上述代码获取帖子计数,并返回所有帖子,但我只想按今天的日期筛选数据。

获取用于获取条款而非帖子的条款

如果你想获得当前日期的帖子,你可以使用下面的代码

$termscat = get_terms([
        'taxonomy' => 'newscategories',
        'orderby' => 'count', 
        'order' => 'DESC',
        'hide_empty' => false

    ]);

你可以得到更多关于这方面的信息,我想你想要这样的东西


选择countpost.ID作为count,rel.term_taxonomy_ID,terms.name从{$wpdb->base_prefix}posts作为post内部连接{$wpdb->base_prefix}term_关系作为rel ON post.ID=rel.object_ID内部连接{$wpdb->base_prefix}terms as terms ON rel.term_taxonomy_id=terms.term_id,其中post_date如“$currentDate%”和post.post_type='$post_type'按rel.term_taxonomy_id按计数排序DESC

解释代码如何回答此问题,可以帮助用户确定它是否适用于他们的情况。Jasbir您无法从get_terms获得今天的计数。这就是为什么可以对当前日期使用WP_查询,然后获得特定分类法的总数。我已经申请了。
$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 );
$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;