到目前为止,我有这个。我想做的是计算特定CPT中两个字段的总值。之后,我想向所有用户更新该总值字段。我知道需要将所有用户id传递给author参数,但这很困难。有可能吗?提前谢谢。
$users = get_users();
$current_id = get_current_user_id();
$args = array( \'post_type\' => \'tip\',
\'posts_per_page\' => -1,
\'author\' => $current_id,
);
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
$the_query->the_post();
$roi = get_post_meta(get_the_id(), \'nasnoviroi\', true) ;
$total += (float)$roi;
} // end while
foreach ($users as $user) {
update_user_meta($user->ID, \'total_roi\', $total);
}