Wordpress - 计算所有具有未来日期到当前日期的帖子 [英] Wordpress - Count all posts that have a future date to the current one

查看:33
本文介绍了Wordpress - 计算所有具有未来日期到当前日期的帖子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找那里来计算未来日期到当前日期的所有帖子

I'm looking for there to count all the posts that are there in future date to the current one

查询:

<?php
    $mostra_data_corrente = date('d-m-Y');
    $query = new WP_Query( array(
        'post_type' => get_option('customer_postquery'),
        'post_status' => 'publish',
        'meta_query' => array(
        array(
            'key' => 'metakey_AMC_data',
        )
    ),
    'date_query' => array(
        'after' => $mostra_data_corrente,
    ),
    'tax_query' => array(
        array(
            'taxonomy' => 'categoria',
            'field' => 'slug',
            'terms' => $queried_object,
        ) 
    ) ) ) ;
    $conta_risultati = $query->found_posts;
    echo $conta_risultati;
?>

地点:

get_option('customer_postquery'):动态检索所有已创建的自定义帖子类型

get_option('customer_postquery'): dynamically retrieves all the custom post types that have been created

metakey_AMC_data:是元键,其中事件(发布)的日期包含在元值中

metakey_AMC_data: is the meta key where the date of the event (post) is enclosed within the meta_value

$queried_object:根据我们所在的页面动态检索帖子的分类,从而根据帖子的分类过滤帖子

$queried_object: dynamically retrieves the taxonomy of posts based on the page we are on, thus filtering the posts based on their taxonomy

所以我的目的是计算所有在未来日期到当前日期的帖子

So my intent is to count all the posts that are there that have a future date to the current one

与当前日期相比,未来某个日期存在的帖子数量无法准确计算"

"It does not count perfectly how many posts exist at a future date compared to the current one"

编辑代码:

<?php
$mostra_data_corrente = date('d-m-Y');
$query = new WP_Query( array(
    'post_type' => get_option('customer_postquery'),
    'post_status' => 'publish',
    'meta_query' => array(
        array(
            'key'       => 'metakey_AMC_data',
            'compare'   => '>',
        )
    ),
    'date_query'     => array(
        'after' => $mostra_data_corrente,
    ),
    'tax_query' => array(
        array(
            'taxonomy' => 'categoria',
            'field' => 'slug',
            'terms' => $queried_object,
        )
    )
) ) ;
$conta_risultati = $query->found_posts;
echo $conta_risultati;

result:3 ,但这不是事实,因为在此分类法的当前日期之后我有 7 个结果

result:3 , but it's not the truth because i have 7 result after current date for this taxonomy

推荐答案

可能你需要像这样查询:

May be you need to query them like :

$currentPostDate = 'get your post date here';
$args = array(
    'post_type' => 'post',
    'meta_key' => 'the_date',
    'meta_query' => array(
        array(
            'key' => 'the_date',
            'value' => $today,
            'compare' => '>='
        )
    ),
);

$your_custom_query = new WP_Query($args);
$postcount = count($your_custom_query);

考虑在您的functions.php文件中将其作为函数.

Think to make it as function in your functions.php file.

这篇关于Wordpress - 计算所有具有未来日期到当前日期的帖子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆