数组的求和或排序值
Sumup or order values of an array
使用以下代码,我可以获得个人预订的总人数。但是,我想根据开始日期汇总值,而不是所有预订的总和。
我每天需要 人 的总数。所以开始日期相同的值。不是所有天的总人数。
$total_count = 0; // Initializing
$reservation_ids = get_posts( array(
'posts_per_page' => -1,
'post_type' => 'arb_reservation',
'post_status' => 'paid',
'start_date' => 'start_date',
'fields' => 'ids',
) );
// Loop through reservation Ids
foreach ( $reservation_ids as $reservation_id ) {
$reservation = new ARB_Reservation( $reservation_id );
$count = array_sum( $reservation->get_person_counts() );
$total_count += $count;
}
你能不能把计数和WP_Query包括在内,见下文:
// define target date
$today = date( 'Y-m-d' );
// build query
$args = array(
'posts_per_page' => -1,
'post_type' => 'arb_reservation',
'post_status' => 'paid',
'date_query' => array(
array(
'after' => $today,
'before' => $today,
'inclusive' => true,
)
),
);
$query = new WP_Query( $args );
// example count
echo count( $query->have_posts() );
使用以下代码,我可以获得个人预订的总人数。但是,我想根据开始日期汇总值,而不是所有预订的总和。
我每天需要 人 的总数。所以开始日期相同的值。不是所有天的总人数。
$total_count = 0; // Initializing
$reservation_ids = get_posts( array(
'posts_per_page' => -1,
'post_type' => 'arb_reservation',
'post_status' => 'paid',
'start_date' => 'start_date',
'fields' => 'ids',
) );
// Loop through reservation Ids
foreach ( $reservation_ids as $reservation_id ) {
$reservation = new ARB_Reservation( $reservation_id );
$count = array_sum( $reservation->get_person_counts() );
$total_count += $count;
}
你能不能把计数和WP_Query包括在内,见下文:
// define target date
$today = date( 'Y-m-d' );
// build query
$args = array(
'posts_per_page' => -1,
'post_type' => 'arb_reservation',
'post_status' => 'paid',
'date_query' => array(
array(
'after' => $today,
'before' => $today,
'inclusive' => true,
)
),
);
$query = new WP_Query( $args );
// example count
echo count( $query->have_posts() );