After I have upgraded ACF plugin, My onchange function JS file is not working anymore on wordpress function.php. I don't know what happened to it. Here is my code. Could you please enlighten me?
irevent_script.JS
(function($) {
$('#acf-field-acf_event_type').on('change', function () {
var selectVal = $("#acf-field-acf_event_type option:selected").val();
if(selectVal=="Others") {
$("#title").val("");
} else {
$("#title").val(selectVal);
}
});
})( jQuery );
In function.php
function irevent_script( $hook_suffix ){
$cpt = 'irevent';
if( in_array($hook_suffix, array('post.php', 'post-new.php') ) ){
$screen = get_current_screen();
if( is_object( $screen ) && $cpt == $screen->post_type ){
//wp_enqueue_script( 'tinymce_js', includes_url( 'js/tinymce/' ) . 'wp-tinymce.php', array( 'jquery' ), false, true );
wp_enqueue_script('irevent_js_script', get_bloginfo('template_url').'/js/irevent_script.js', array('jquery'), '4.7.5', true);
}
}
}
add_action( 'admin_enqueue_scripts', 'irevent_script');
I found that event type ID has been changed after ACF upgraded.So, I had to change event type ID in javascript as well. Now, it works.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.