Retrieving data right after saving

Support General Retrieving data right after savingResolved

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #19033
    DaveDave
    Participant

    Hi Ahn,

    I've got a strange issue. That I'm not sure how to solve.

    I am using MB Custom Table to store my data and the MB Frontend Submission was not good enough for my needs. I created my own API routes and I'm performing CRUD operations with global $wpdb methods.

    Here is the problem. When I update a column in the custom table with $wpdb->update() and then I run rwmb_meta( 'field_name', null, $ID ) the returned information from the rwmb_meta() is not the updated values. I was running this example with an oembed type field. I am storing a YouTube url but I want to return the updated html to the user.

    #19046
    Long NguyenLong Nguyen
    Moderator

    Hi Dave,

    If you are using the custom table to save the value, please use this code to get the value

    $value = rwmb_meta( $field_id, ['storage_type' => 'custom_table', 'table' => $table_name] );
    echo $value;

    and regarding the Oembed type, you can use the function rwmb_the_value() which outputs the HTML of the field.

    For further information, please follow the documentation
    https://docs.metabox.io/extensions/mb-custom-table/#getting-field-value
    https://docs.metabox.io/rwmb-the-value/

    #19593
    DaveDave
    Participant

    Unfortunately, this did not work. No change.

    I've dug into the code to try and figure out what is going on and I keep coming back to this function.
    'public static function call()' in this file '/inc/field.php'.

    It calls 'call_user_func_array( array( RWMB_Helpers_Field::get_class( $field ), $method ), $args )' but I'm confused where this goes.

    Remember, I'm updating the custom table in the database manually with $wpdb->update() and then calling rwmb_meta( $field_id, ['storage_type' => 'custom_table', 'table' => $table_name] ); right afterwards.

    The issue is that I'm calling these in the same server request. If I send another request and ask for the data with rwmb_meta(), it comes back correct.

    The reason I need this to work is that I'm also using FacetWP and I want to index a post after saving. When I run the FacetWP index function the data it's using to index is INCORRECT!

    #19595
    Anh TranAnh Tran
    Keymaster

    Hi Dave,

    It might relate to how rwmb_meta work with custom tables. We implemented a cache layer for the custom table storage, the code is in the inc/class-rwmb-table-storage.php, which is like this:

    public function get( $object_id, $meta_key, $args = false ) {
        if ( is_array( $args ) ) {
            $single = ! empty( $args['single'] );
        } else {
            $single = (bool) $args;
        }
        $default = $single ? '' : array();
    
        $row = MB_Custom_Table_Cache::get( $object_id, $this->table );
    
        return ! isset( $row[ $meta_key ] ) ? $default : maybe_unserialize( $row[ $meta_key ] );
    }

    In this case, as you already use $wpdb to update data, I'd suggest using it to get data to avoid the caching problem.

    #19606
    DaveDave
    Participant

    Thank you Anh!

    I went to inc/class-mb-custom-table-cache.php and set $row = false; in the get() function. Then it fixed things (even though I won't have the benefit of the caching).

    The FacetWP is still complaining but it may be because of something else.

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.