-
-
Save pauloiankoski/ac86f6cd467cbb2351d3e61641a40c62 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery(document).ready(function($)) { | |
var preventSubmit = true | |
$('.acf-field[data-name="repeater_value"]').hide() | |
$('.wp-admin.post-type-page form#post').on('submit', function(e) { | |
if ( ! preventSubmit ) { | |
return | |
} | |
e.preventDefault() | |
var table = [] | |
$('.acf-field[data-name="repeater_name"] .acf-row:not(.acf-clone)').each(function(row){ | |
table[row] = [] | |
$(this).find('input').each(function(column){ | |
table[row][column] = $(this).val() | |
$(this).attr('disabled', true) | |
}) | |
}) | |
$('.acf-field[data-name="repeater_value"] textarea').val(JSON.stringify(table)) | |
preventSubmit = false | |
$(this).submit() | |
preventSubmit = true | |
$('.acf-field[data-name="repeater_name"] .acf-row input').removeAttr('disabled') | |
}) | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action( 'acf/load_value/name=repeater_name', function( $value, $post_id, $field ) { | |
$table = json_decode( get_field('repeater_value', $post_id) ); | |
if ( ! $table ) { | |
return $value; | |
} | |
$keys = wp_list_pluck( $field['sub_fields'], 'key' ); | |
$new_value = array(); | |
foreach ( $table as $row => $columns ) { | |
foreach ( $columns as $column => $value ) { | |
$new_value[ $row ][ $keys[ $column ] ] = $value; | |
} | |
} | |
return $new_value; | |
}, 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment