• Resolved Windurin

    (@windurin)


    Hi,

    I have quite a few custom post types on my site, as well as custom taxonomies connected to them, all added with CPTUI. I’ve recently noticed that on a page where I have the form to add one of the custom post types, all of the custom taxonomies have some terms already added:

    View post on imgur.com

    It’s always the same terms pre-filled upon refresh. My first instinct was that the terms had somehow been applied to the page itself where the form was. However, I’ve tried adding the form to a new page and it’s the same result. I’m using the plugin ACF Frontend Form for the forms so thought it might be related to that, but even if I add the form with a shortcode from the ACF Extended form builder or add the form directly with PHP, it’s the same.

    I narrowed the issue down to the Load Terms option in ACF when editing the Field Group. If I disable Load Terms, then the fields are empty on the page to add the new post, but I need Load Terms for editing those post of this custom post type. Plus, all the other custom post types/custom taxonomies don’t have this issue so I don’t really understand why it’s only happening with this one?

    I’ve tried creating a new ACF Field Group with the same taxonomies: same result. I’ve tried renaming the custom taxonomies (migrating the slugs) and the taxonomy ACF field slugs: same result. The only thing that essentially works is creating a new custom taxonomy but then I’d have to add in all the terms and update every post (there’s hundreds), plus update the field name/taxonomy slugs on all my templates. If it was just one of the custom taxonomies attached to this post type, I might just go ahead and do that, but for whatever reason it’s ALL the custom taxonomies attached only to this post type.

    It’s almost as if the custom taxonomies themselves are corrupted/have those terms somehow attached to them permanently. And since it appears to be related to the custom taxonomies themselves (which were added with CPTUI), I figured I would ask here if you’ve ever come across this issue and why it might be happening? As well as any solutions of course. Thanks a lot.

    • This topic was modified 5 years, 6 months ago by Windurin. Reason: typos/spelling
Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter Windurin

    (@windurin)

    UPDATE: I’ve managed to figure this out after days of searching! It was related to the database table wp_term_relationships

    This post here helped point me in the right direction:

    https://scottnelle.com/648/clean-bloated-wp_term_relationships-table/

    After running that query I did find some orphaned/null entries and I could tell by cross-referencing some of the meta_id’s that they matched up to the ones that were always showing up when adding a new post of this post type. After deleting those entries, the form for adding a new post of that post type now has all custom taxonomies empty by default, while still being able to have Load Terms enabled for loading the on editing forms.

    Sorry for considering that it might be related to CPTUI – sometimes it just comes down to knowing the right terms to Google 🙂

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Not sure what to suggest here, to be honest.

    The only thing CPTUI is doing in this case is making sure the taxonomies and post types are being registered at the appropriate time. Why terms are being auto selected or not would be more on the shoulders of the ACF addons here.

    Worth reaching out to their support to see what they have to say about this issue, since it’s their plugins being integrated with.

    However, do let me know what they say, as it is a curious issue.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    And I didn’t refresh before submitting.

    Glad to hear you found a solution already.

    Hello,

    ACF Extended developer here! Concerning the actual ACF Field “Load Terms” settings, in fact this setting is used on both front-end and back-end. The problem come from the fact that’s you’re using the same field group for both the back-end (edit post) and front-end (add post). ACF will use that setting the same way on both sides (which makes sense).

    There different ways to fix that behavior:

    1. Using custom code

    You can add the following code in your functions.php file, in order to disable the preloaded value when the field is rendered on the front-end:

    add_filter('acf/load_value/name=my_terms_field', 'my_acf_terms_field_front_end', 10, 3);
    function my_acf_terms_field_front_end($value, $post_id, $field){
        
        // Bail early if in the admin screen
        if(is_admin())
            return $value;
        
        // Disable preloaded value
        $value = null;
        
        // return
        return $value;
        
    }
    

    2. Use the “Advanced Field Settings” feature

    An another solution that can be performed without any code, is to use the “Advanced Settings” feature of ACF Extended which let you customize (enable/disable) field settings based on the current screen. See odcumentation: https://www.acf-extended.com/features/field-settings/advanced-settings

    You’ll need to set the load_terms setting to false on the “Front-end screen”. See screenshot: https://i.imgur.com/7pPR1uS.jpg

    Hope it helps!

    regards.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Thanks for chiming in with the extra info @hwk-fr

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Terms Being Automatically Loaded on Custom Taxonomies’ is closed to new replies.