Created
April 12, 2018 23:55
-
-
Save dnavarrojr/b098d57ec9ffd0a1d391cdd86ac493ea to your computer and use it in GitHub Desktop.
ACF action "acf/input/admin_footer" not working with get_field_objects()
This file contains 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
<?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' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?