我找到了问题的原因。由于我处理的帖子类型是woccommerce orders(shop\\u order),因此我必须正确输入帖子状态。
编辑代码如下:
add_action(\'save_post\', \'change_child_posts_meta\', 10, 2);
add_action(\'post_updated\', \'change_child_posts_meta\', 10, 2);
function change_child_posts_meta($post_id, $post)
{
if ( $post->post_parent == 0 && \'shop_order\' == $post->post_type) {
$mettta = get_post_meta( $post->ID , "_post_color" , true );
$args = array(
\'numberposts\' => -1,
\'post_type\' => \'shop_order\',
\'post_parent\' => $post->ID,
\'post_status\' => array(\'wc-pending\',\'wc-processing\',\'wc-on-hold\',\'wc-completed\',\'wc-cancelled\',\'wc-refunded\',\'wc-failed\',\'wc-shipping-progress\')
);
$ChildIDs = get_posts( $args );
foreach ($ChildIDs as $childID) {
update_post_meta( $childID->ID, "_post_color", $mettta );
}
}
}