Home › Forums › General Issues › Using .load() Results in 'Uncaught Error'
Hello,
I have a setup that’s rather unique as far as using ACF goes, and I think I’m trying to do something that’s either not allowed, or I’m simply doing things incorrectly.
The situation: I have a form on my client’s site that contains a <select> called #campus. When an <option> is selected from #campus, a second (conditional) <select> called #program appears, and contains a list of <option>s that is unique to the selected #campus <option>.
Because of certain constraints (I’m picking this site up from a previous developer), I built out a jQuery function that uses .load() to load a .php file into #program that contains the appropriate <option>s based on whatever #campus <option> the user selects. Up to this point, everything has been working properly.
Here’s where it started to break: In an attempt to be able to add/remove/edit the #program <option>s from the WP backend, I created an ACF Repeater and added it to one of the .php files that contains a set of #program <option>s. The code looks like this:
<?php
if( have_rows('programs', 'option') ):
while ( have_rows('programs', 'option') ) : the_row(); ?>
<option value="<?php the_sub_field('program_value', 'option'); ?>"><?php
the_sub_field('program_copy', 'option'); ?></option>
<?php endwhile;
endif;?>
So, basically, I’m trying to use jQuery to .load() in a .php file that contains ACF Repeater code and it’s returning the following error: Uncaught Error: Call to undefined function have_rows()
Any help? I hope I was able to explain everything clearly.
The problem is that nothing in WP is loaded if you are trying to load the content of a specific PHP file using AJAX.
In order to have access to all WP and plugin function you must make all request through /wp-admin/admin-ajax.php, setting the required “action” and creating the needed WP filters rather than requesting a specific file. This page explains AJAX in WP, it says AJAX in Plugins, but the information is relevant to all AJAX requests in WP.
Sorry, you wrote ‘this page’ but I don’t see a hyperlink. Did you forget to add one or am I misunderstanding? Either way, thank you for the help, it has definitely steered me in the right direction.
it looks like I did π https://codex.wordpress.org/AJAX_in_Plugins
You must be logged in to reply to this topic.
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!
ποΈ Just one more day until the next session of ACF Chat Fridays! Make sure to register for the latest updates on whatβs coming in ACF 6.1!
— Advanced Custom Fields (@wp_acf) March 30, 2023
π Friday 31st March 3pm UTC
π Register here - https://t.co/3UtvQbDwNm pic.twitter.com/7xtEJakeQN
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.