Support

Account

Home Forums ACF PRO Taxonomy field not loading values in acf_form()

Solving

Taxonomy field not loading values in acf_form()

  • I’m trying to use acf_form() as a front-end post editor, but I’m having issues with taxonomy fields, specifically them as Select and Multi Select appearances. Every time I try choosing an option, no taxonomies get loaded and instead the field returns “The results could not be loaded.” It works fine inside wp-admin, just not on the front end with acf_form().

    The code I’m using is pretty vanilla, so I’m not sure if I’m missing something huge.

    <?php acf_form(array(
        'post_id' => $post->ID,
    )); ?>

    Using ACF PRO v5.6.1. Any help would be appreciated.

    EDIT:
    In addition to this, clicking the “Add New [taxonomy]” plus sign still generates a modal window, but instead of a Name field and Parent dropdown, all that’s returned after the modal head is “0”.

    I tried swapping Select2 v4 with v3 in the acf core, but I was presented with the same issue.

  • There are some things I can think of that can cause this.
    1) you to not a call to acf_form_head() before get_header() (before any content is output)

    2) there is a JavaScript error of some kind, check console

    3) there is a php error during the AJAX call, turn on error logging and see if there’s an error https://codex.wordpress.org/WP_DEBUG

  • Hi John, thanks for your reply.

    1) acf_form_head() is the first function on my template file, as <?php acf_form_head(); get_header(); the_post(); ?>

    2) No JS errors were returned in the console when trying to load taxonomies. Is there a need/method to turn on any verbose logging?

    3) Turning on WP_DEBUG and WP_DEBUG_LOG didn’t return any errors on the page or in my logs.

    I tried creating a fresh WP install at http://acftax.wpengine.com/?p=1 with the default 2017 theme. Everything is vanilla except for code inside the loop. single.php‘s code in its entirety is attached.

    
    <?php acf_form_head(); get_header(); ?>
    
    <div class="wrap">
    	<div id="primary" class="content-area">
    		<main id="main" class="site-main" role="main">
    
    			<?php
    			/* Start the Loop */
    			while ( have_posts() ) : the_post();
    
                    echo '// START <code>acf_form()</code>';
                    acf_form(array(
                        'post_id' => $post->ID
                    ));
                    echo '// END <code>acf_form()</code>';
    
    			endwhile; // End of the loop.
    			?>
    
    		</main><!-- #main -->
    	</div><!-- #primary -->
    	<?php get_sidebar(); ?>
    </div><!-- .wrap -->
    
    <?php get_footer();
    

    And I still get the same error, leading me to believe this is an issue within ACF or Select2.

    Any additional assistance on this would be greatly appreciated. Thanks!

  • Would love some additional assistance on this. Thanks!

  • I’ve done testing and I cannot recreate the issue that you’re seeing, using the same code.

    Are there any other plugins installed other than ACF?

  • No other plugins are installed.

    This issue is getting stranger as time goes on. On my test environment (http://acftax.wpengine.com/?p=1), those taxonomy fields randomly started working. However, on my staging environment, they’re obviously still broken. I tried switching themes to Twentyseventeen, re-adding my custom fields and taxonomies, and adding the acf_form snippet, and instead of “The results could not be loaded”, I got “No results found”

    Are their arguments that might be required with register_taxonomy for custom post type taxonomies to work correctly with ACF’s taxonomy field inside acf_form?

  • I too have this problem.

    I have a custom taxonomy field that looks like this:

    		register_taxonomy('product_category', 'product', array(
    		  'hierarchical'    => true,
    		  'label'           => 'Product Category',
    		  'meta_box_cb'     => false, // Use ACF to display
    		  'show_in_quick_edit' => false,
    		  //'rewrite'           	=> array( 'slug' => 'cat', 'with_front'=>false ),
    		));

    However when I use this within a Select field, no options are provided?

    I have had to resort to keeping this a Radiobox for now, however I have Sub Categories as well, so the form is getting quite large.

    Any help would be MUCH appreciated.

  • Looking back on this, I noticed something. For me, the issue only appears to happen when NOT logged into wp-admin. @hube2, if you’d like I can send you the WP admin name and PW to the install I linked above for you to confirm.


    @jsette7
    are you able to check this out as well?

  • Hmmm that doesn’t help me much as only Authenticated Users can add products.

    I think I may need to resort to manually creating a form and new post… I don’t see any resolution to this issue anytime soon

  • This is just a guess, but it’s what I think is going on. Since the select2 field is loaded using AJAX then somehow WP is blocking the ACF from getting the list of terms from the taxonomy if the user is not logged in.

    At any rate, something is preventing the AJAX request from completing.

    That being said, I just tried a taxonomy field, on a font end form using acf_form(), while logged out and it works perfectly. This is using current version of WP, 2017 them, ACF Pro and no other plugins and testing using the built in “category” taxonomy.

  • Hi there,

    Also struggling with this one and I’m using a custom taxonomy on a custom post type. The multi-select works find on the backend when editing the custom post type, but when rendering the form on the front-end (logged in or not) then I just get an empty select.

    There are no JS error and also no HTTP requests issues. All assets are loaded fine.

    Any movement on this?

  • This reply has been marked as private.
  • I’m having a similar issue with a custom taxonomy field and acf_form(). The taxomnomy field is showing the right value in the backend, but radio buttons are empty on the form on the frontend. That is, until I save the post again (either from the front- or backend).

  • I’m having a similar problem. Using a custom taxonomy and a select in a repeater. The taxonomies is not showing up (even when I’m logged out), the select element is empty, works in admin.

    I’m using the latest version of ACF Pro.

    The error-log generated the following:

    [19-Jul-2018 10:46:02 Europe/Stockholm] PHP Notice: Undefined property: WP_Error::$term_id in C:\www\site-name\wp-content\plugins\advanced-custom-fields-pro\includes\fields\class-acf-field-taxonomy.php on line 658

    [19-Jul-2018 10:46:02 Europe/Stockholm] PHP Notice: Undefined property: WP_Error::$term_id in C:\www\site-name\wp-content\plugins\advanced-custom-fields-pro\includes\fields\class-acf-field-taxonomy.php on line 257

  • Same problem, How ever loggin in as an none admin gives me the same problem. If i log in as a user with a custom role that user still can’t select the posts.

    Is there already an update on this ticket?

  • Same problem. I use checkboxes. When I check some terms for one post in the backend, only the checked terms are shown in the frontend, for all posts.

  • Same problem for me too : I can’t load custom taxonomies, and this bug seems to appear randomly.
    I’ve also spent 2 days trying to fix that, with no result…

  • It seems to me that only the radio button “term object” doesn’t return the values : when I switch to “term ID”, I can get the term slug, name, etc.
    Look like there is an init issue, has anyone an idea ?

  • So I think I managed to fix this for me… Apparently the jQuery version & jQuery migrate was colliding with the version used when enqueueing scripts from ACF / WordPress. It gave no errors so I didn’t catch it at first. So I excluded my version of jQuery & Migrate from the specific templates and now it’s working as intended. I hope it helps!

  • Hi,

    I had the same issue then discovered it was ( in my case ) the Autoptimize Plugin (
    Optimize JavaScript Code? ) that restricted the AJAX load :::

  • This reply has been marked as private.
Viewing 21 posts - 1 through 21 (of 21 total)

The topic ‘Taxonomy field not loading values in acf_form()’ is closed to new replies.