Home › Forums › Gutenberg › Get option page fields from block (not a AFC block) › Reply To: Get option page fields from block (not a AFC block)
I do not use blocks, so this is just a guess and based on getting options pages and adding them to JS in a page.
There are a couple of choices.
If the script that needs values is “Enqueued” then you need to localize the script https://developer.wordpress.org/reference/functions/wp_localize_script/
If the script is output into the page then you need to output the values to JS variables on the php side.
<script>
var some_varialble_name = '<?php the_field('some_field_name', 'options'); ?>';
</script>
Or some combination of these things.
The only other choice is to have an AJAX request in your script that gets the option values.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.