I’m using Fancybox 2 to create a popup disclaimer box when a certain link is clicked on my site. The Disclaimer content is in a separate PHP file I added to a /popup/ directory inside my WordPress theme.
The issue is when I try to display a value from my ACF global content, it must be throwing a PHP error because the popup is then completely blank. Here’s my ACF code in the PHP file:
<?php the_field('popup_box_title', 'option'); ?>
How can I get this file to pull in ACF values?
When you say that this is a file, do you mean that is loaded with some type of AJAX? In other words, the file is loaded directly without invoking the WP start up and everything that goes with it?
Correct. Basically, I made a new HTML file and placed in my own /popups/ directory that I created inside my theme folder. This is the entire HTML inside that file:
<h4><?php the_field('popup_box_title', 'option'); ?></h4>
<p>Diclaimer text goes here...</p>
<a href="#" title="">Accept</a>
<a href="#" title="">Cancel</a>
And inside one of my WP pages is a link that loads this HTML file in a Fancybox popup.
To populate the popup_box_title field inside WordPress, I created a Global field in my options page (https://www.advancedcustomfields.com/resources/options-page/).
The problem is that global field isn’t working on the popup HTML.
You can’t do AJAX that way in WP. Basically, none of the functions for WP or any plugins will be defined. See this document on using AJAX in WP https://codex.wordpress.org/AJAX_in_Plugins. You either need to go through admin-ajax.php or you need to load all the WP stuff at the top of your file. The first one is considered the correct way to do this, the second is considered a hack.