Your question is not entirely clear, but it looks like you are in need of wp_localize_script
, which allows you to pass variables from PHP to a script. You would use it like this (example with two fields):
add_action ('wp_enqueue_scripts','wpse244551_add_field');
function wpse244551_add_field () {
$my_field = array ();
$my_field[] = array (field1 => get_field ('field1'));
$my_field[] = array (field2 => get_field ('field2'));
wp_localize_script ('my-script', 'MyFields', $my_field);
}
Now, in the script you have registered with the handle my-script
you can access the variable with MyFields.field1
and MyFields.field2
.
Related Posts:
- jQuery: using a variable as a selector [duplicate]
- how to define variable in jquery
- JSON output returns page source code [closed]
- get value from selected input
- oEmbed Video in Modal
- Get with jQuery the value of an ACF field
- Theme customisation – how to store javascript externally when it utilises php variables?
- jQuery dialog prints HTML-Tags under WordPress
- ACF link withing website is good, but not external link?
- Accessing Advanced Custom Fields with Repeater using jQuery instead of PHP
- jQuery $(this) keyword
- JavaScript error (Uncaught SyntaxError: Unexpected end of input)
- Disable button in jQuery
- JavaScript error (Uncaught SyntaxError: Unexpected end of input)
- $.ajax – dataType
- How can I get the ID of an element using jQuery?
- How do you select a particular option in a SELECT element in jQuery?
- How to use jQuery qTip?
- Installing jQuery?
- Email validation using jQuery
- Wildcards in jQuery selectors
- jQuery: How can I create a simple overlay?
- XML Parsing Error: not well-formed in FireFox but good in Chrome
- jQuery get value of selected radio button
- How to make Bootstrap carousel slider use mobile left/right swipe
- javascript function wait until another function to finish
- Clear form fields with jQuery
- How to use radio on change event?
- How can I change the text color with jQuery?
- How to get mouse position in jQuery without mouse-events?
- Show div #id on click with jQuery
- How can I change CSS display none or block property using jQuery?
- Is there a way to enable Cross-Origin Resource Sharing for WordPress’ ajaxurl?
- How to get attachment id as soon as it is uploaded through media uploader in jquery?
- Using ‘$’ instead of ‘jQuery’ in WordPress
- AJAX call returns 0
- Is it possible to get the logged in username in a jquery script?
- Gravity Forms loading jquery
- Extend 3.5 media uploader plugin to change button name
- Javascript included but alert() function not working
- Adding fields to the media uploader with jquery listeners
- Bind to WPSetAsThumbnail
- Cannot access elements of json object
- Script won’t execute in the media manager
- Basic ajax call in WordPress
- jQuery Validate wp_editor
- Using jQuery to retrieve customizer value
- How do I setup nested repeatable option fields?
- What are best practices for including jquery plugins
- wp_enqueue_scripts hook is not being called
- How to enable the content editor as a droppable target with jQuery-ui?
- Enqueue Google CDN jQuery in Footer
- ‘jQuery is not defined Error’ appearing in load-scripts.php
- Dealing with a library that depends on jQuery
- Override theme style with other CSS on a specific page
- Ajaxify calendar
- How can I load jquery library into my dashboard widget?
- Accessing user Meta data via REST and backbone
- Problem with tables (huge data) on Word-press site
- start.js:45TypeError: Not enough arguments on Safari [closed]
- Passing a varible from jQuery to PHP
- Vanderlee jQuery color picker and WordPress Errors
- Dropdown filtering extremely slow
- filterable portfolio with wordpress and jquery
- Adding a slide toggle on WordPress
- I have an old version of jQuery showing up. How do I figure out where it is coming from?
- How to change background image from WordPress Gallery
- Search input area autogrow – how?
- Populating shortcode values dynamically in theme template
- WordPress Rotating Background Images
- Trying to Load jQuery
- Jquery contact form to send mail to admin [closed]
- Can user meta be shown or hidden depending on user logged in status?
- Screen Options JavaScript Code
- Is there some jQuery conflict here?
- Theme has superfish – how to add supersubs?
- Absolute path to stylesheet_dir/images/my_img.jpg does not work?
- Which hook to use when adding ajax to viewer-facing side?
- jquery bookmark links
- WordPress and Modal Popup – how to make the already loaded javascript assets available in modal?
- Theme style overrides the plugin style
- Storing current page WP list table HTML data into a PHP variable
- jQuery .html rendering [closed]
- Special Characters and Spaces are not transferred correctly via AJAX call.
- How to manipulate elements on the Insert Media Attachment settings popup
- Site images are fixed in front of my site content [closed]
- jQuery not working for media uploader
- Adding text to links when not on the homepage
- how to remove/exclude html coding from json file while export?
- WordPress and Raty.js
- search in jquery mobile returns blank page
- Uncaught TypeError: undefined is not a function (shortcode-box)
- Group posts by weekly or monthly
- adding the full image path to a wordpress javascript file
- Ensure an external javascript file called from plugin is loaded after jquery is called
- jQuery not working for tabs shortcode [closed]
- Why my vertical tab js code is refreshing the page continuously? [closed]
- jQuery cycle thumbnails?
- Generate dynamic ID’s for each accordion button
- Impossible to update jQuery version from 3.1.0