admin管理员组文章数量:1327676
I'm trying to store in a variable the content of an ACF field so that later on I can use it in a jQuery function using the plugin "Simple Custom CSS and JS".
I found what I thought was the answer in the following link Get ACF value in external jQuery document but I'm getting an error inside the console saying "Uncaught ReferenceError: MyFields is not defined".
This is my PHP code:
add_action ('wp_enqueue_scripts','wpse244551_add_field');
function wpse244551_add_field () {
$my_field = array ();
$my_field[] = array ('field1' => get_field ('variable_product_html'));
wp_localize_script ('myScript', 'MyFields', $my_field);
}
This is my jQuery code (Note: I'm using the Simple Custom CSS and JS to write my code):
jQuery(document).ready(function( $ ){
function myScript() {
var phpValue = MyFields.field1;
console.log(phpValue);
}
myScript();
});
本文标签: Get with jQuery the value of an ACF field
版权声明:本文标题:Get with jQuery the value of an ACF field 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742222480a2435533.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论