1

For some reason my update_post_meta() function does not accept an array. Normally the function serializes the array by itself, but now I need to do this by myself, otherwise it does not update.

Could this be, because I call it inside a Class?

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();
  • What is the update_post_meta returning? Also, what does the data look like in the database? – Tom Jan 28 '16 at 11:30
  • @Tom Nothing, it is not storing the data.. – Robbert Jan 28 '16 at 12:23
  • He asked what it returned, not what it did. – s_ha_dum Jan 28 '16 at 14:23
  • I mean if you assign a variable to the update_post_meta function what does it return? Like this: $returnData = update_post_meta( $post_id, 'order_data', $order_data ); print_r($returnData); – Tom Jan 28 '16 at 17:34
  • @Tom It returns the meta ID. So it looks like it is stored without value.. – Robbert Jan 28 '16 at 17:38
0

The problem was in my way of including some classes with the spl_autoload_register() function. This leaded into some problems inside the WordPress core. Excuse me for not testing this before.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.