Support Forum » User Profile

Forum Replies Created

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • in reply to: Update a CF stored in a custom table, based on another CF #38070
    LauGauLauGau
    Participant

    Just tested and it's working with the custom table API:

    
    $object_id = 532;
    $table = 'websites';
    
    $exists = \MetaBox\CustomTable\API::exists( $object_id, $table );
    
    if ( $exists ) {
        
        // Get the monthly quota
        $data = \MetaBox\CustomTable\API::get( $object_id, $table );
        $quota_monthly = $data['time_credit_monthly'];
        
        // Update the quota usage
        $data['time_credit_left'] = $quota_monthly;
        // and we re-save the data
        \MetaBox\CustomTable\API::update( $object_id, $table, $data );
    }
    

    So there is definitely a weird behavior on the rwmb_set_meta() function.

    in reply to: Update a CF stored in a custom table, based on another CF #38069
    LauGauLauGau
    Participant

    Xin Chao Long,

    Actually, I am using the Meta Box UI to declare those :
    https://share.cleanshot.com/W2CH8urnV772nFGLkt4F

    This is the current code:

    
    add_action( 'init', function() {
    
        $table_name = 'websites';
        $post_id = 532; // test on a specific post
        
        // we get the monthly credit
        $time_credit_monthly = rwmb_get_value( 'time_credit_monthly', [
            'storage_type' => 'custom_table',
            'table'        => $table_name],
            $post_id );
    
        // we reset the quota with the monthly credit
        $field_id = 'time_credit_left';
        $value = $time_credit_monthly;
        rwmb_set_meta( $post_id, $field_id, $value, [
            'storage_type' => 'custom_table',
            'table'        => $table_name,
        ] );
            
    }, 99 );
    

    Thanks again for your help.
    In the same time I will have a look at the Custom Table API.

Viewing 2 posts - 1 through 2 (of 2 total)