For anyone where $field.data('key')
is invalid, the following code worked for me.
The main difference is that you’re targeting $field[0]['dataset']['key']
.
<?php
// Set the default color palette for certain fields
function set_acf_color_picker_default_palettes() {
?>
<script>
let setDefaultPalette = function() {
acf.add_filter('color_picker_args', function( args, $field ){
// Find the field key
let targetFieldKey = $field[0]['dataset']['key'];
// Set color options for the field
// if field is accordion_icon_background_color
if ( 'field_60d621b2f0e04' === targetFieldKey ) {
args.palettes = [ '#999', '#ae241a', '#004990' ];
}
// Return
return args;
});
}
setDefaultPalette();
</script>
<?php
}
add_action('acf/input/admin_footer', 'set_acf_color_picker_default_palettes');
Thank you, John. I appreciate your advice.
You made excellent points here.
Thanks, John. I hadn’t thought of that.
What do you think the advantages would be if we loop through posts of a custom post type, rather then looping through repeater fields?