Home Forums Backend Issues (wp-admin) AJAX issue with ACF Javascript


AJAX issue with ACF Javascript

  • I have a front end form that allows logged in users to submit data.

    I have a dropdown that grabs data from another post type.

    That dropdown is giving me a “Loading error…” when attempting to use it if I am logged in as a user instead of an admin.

    I tracked it down to a code snippet I added to prevent non-admins from accessing the back end of the site. It appears that it’s also preventing AJAX calls from non-admins.

    Does anyone have a similar code snippet that works with AJAX or know how I can detect an AJAX call and allow it?

  • Okay, I added a check for wp_doing_ajax() and I no longer get “Loading error…”. I now get “No matches found” when logged in as a user. It works fine when I’m logged in as an admin.

    Here is my code:

    add_action( 'init', 'am_block_user_from_admin' );
    function am_block_user_from_admin() {
      if ( wp_doing_ajax() )
      if ( is_admin() && ! current_user_can( 'administrator' ) ) {
        wp_redirect( home_url() );
Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘AJAX issue with ACF Javascript’ is closed to new replies.