出于某种原因,我的update_post_meta()
函数不接受数组。通常情况下,该函数会自行序列化数组,但现在我需要自己完成此操作,否则它不会更新。
这可能是因为我把它叫做类内吗?
My code:
class Checkout {
// Initializes object, calls the init hook
public function __construct( $testMode = false ) {
// Calls the init hook
add_action( \'init\', array( $this, \'setup\' ) );
}
public function setup() {
// Insert a post
$post_id = wp_insert_post( array( \'post_title\' => \'Post title\', \'post_content\' => \'\', \'post_type\' => \'transaction\', \'post_status\' => \'publish\' ) );
// Create order data array
$order_data = array(
\'subtotal\' => 100,
\'vat\' => get_option( \'vat_percentage\' )
);
// Update order price
update_post_meta( $post_id, \'order_data\', $order_data );
}
}
// Call object
$checkout = new Checkout();