0

我有 100 个帖子都有一个名为“isactive”的元键,其值为“1”或“0”

我需要计算任意 2 个日期之间的活动帖子数量的百分比(来自 'isactive' 元键值)

$args0 = array(
    'date_query' => array(
        array(
            'after'     => 'January 1st, 2013',
            'before'    => array(
                'year'  => 2013,
                'month' => 2,
                'day'   => 28,
            ),
            'inclusive' => true,
        ),
        'meta_key' => 'isactive',
        'meta_value' => 0
    )

);
$count0 = new WP_Query( $args0 );

    $args1 = array(
    'date_query' => array(
        array(
            'after'     => 'January 1st, 2013',
            'before'    => array(
                'year'  => 2013,
                'month' => 2,
                'day'   => 28,
            ),
            'inclusive' => true,
        ),
        'meta_key' => 'isactive',
        'meta_value' => 1
    )

);
$count1 = new WP_Query( $args1 );

echo $percent = $count0/$count1;

这种查询是否有效?

还有没有更好的方法来计算基于 2 个日期之间的元键值的百分比?

4

0 回答 0