• Resolved thomstratton

    (@thomstratton)


    When the table field is on an ACF options page https://www.advancedcustomfields.com/resources/options-page/

    update_field does not work.

    see also https://github.com/johannheyne/advanced-custom-fields-table-field/issues/10 although the thread there diverges a bit into updates and fixes that are not related strictly to options page.

    see below a monkey patch to get this functionality working.

    class-jh-acf-field-table.php in update_value function

    function update_value( $value, $post_id, $field ) {
    
        if ( is_string( $value ) ) {
    
            $value = wp_unslash( $value );
            $value = urldecode( $value );
            $value = json_decode( $value, true );
        }
    
        // UPDATE via update_field() {
    
            if (
                isset( $value['header'] ) OR
                isset( $value['body'] )
            ) {
    
                // try post_meta
                $data = get_post_meta( $post_id, $field['name'], true );
    
                // try term_meta
                if ( empty( $data ) ) {
    
                    $data = get_term_meta( str_replace('term_', '', $post_id ), $field['name'], true );
                }
    
                // begin monkey patch for options table
                // error_log('acftf-monkeypatch.post_id' . json_encode($post_id));
                // error_log('acftf-monkeypatch.field[name]' . json_encode($field['name']));
    
                //try options
                if ( empty( $data ) AND
                        ( $post_id = 'options' OR
                        $post_id = 'option'
                        )
                    ) 
                {
                    $data = get_option('options_' . $field['name']);
                    // error_log('acftf-monkeypatch option data: ' . json_encode($data));
                }
    
                // end monkey patch
    
                // prevents updating a field, thats data are not defined yet

Viewing 1 replies (of 1 total)
  • Plugin Author Johann Heyne

    (@jonua)

    Should be fixed with the last release. Thanks for reporting me that issue!

Viewing 1 replies (of 1 total)
  • The topic ‘table field on an options page’ is closed to new replies.