Skip to content

Instantly share code, notes, and snippets.

@dnavarrojr
Created April 12, 2018 23:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dnavarrojr/b098d57ec9ffd0a1d391cdd86ac493ea to your computer and use it in GitHub Desktop.
Save dnavarrojr/b098d57ec9ffd0a1d391cdd86ac493ea to your computer and use it in GitHub Desktop.
ACF action "acf/input/admin_footer" not working with get_field_objects()
<?php
function dave_acf_code_master_footer() {
$id = get_the_ID();
$field = get_field_object( 'code_type', $id );
$field_label = esc_attr( 'acf-' . $field['key'] );
?>
<script type="text/javascript">
jQuery( document ).ready( function() {
function setEditorCodeType() {
var editor = ace.edit( jQuery(".editor")[0] );
editor.session.setMode( "ace/mode/" + jQuery("<?= $field_label; ?>").val() );
}
jQuery("<?= $field_label; ?>").change( function() { setEditorCodeType(); });
setEditorCodeType();
});
</script>
<?php
}
add_action( 'acf/input/admin_footer', 'dave_acf_code_master_footer' );
@dnavarrojr
Copy link
Author

So get_field_objects() returns an empty value if you are creating a new post. But it works if you are editing an existing post...

So how do I get the field key when creating a new post?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment