Support

Account

Home Forums General Issues Update Taxonomy With ACF Fields

Solved

Update Taxonomy With ACF Fields

  • Hi everyone,

    I have a quick question on updating a custom taxonomy via ACF fields in Posts. Here’s the basic scenario:

    I have a custom taxonomy called “Members” which has the default name, slug, and description fields. The purpose was so I could easily display Posts by different Members without the hassle of creating actual User accounts since the whole site is managed by one person.

    Using the Taxonomy field, I have no problem attributing Posts to existing Members but what I’d also like to be able to do is create a new Member within a Post if they don’t exist already.

    What’s the easiest way to do this so that the Members taxonomy is correctly updated via ACF fields within Posts?

    Thanks for your time!

  • It really depends on how you’re using this. Is this a front end form or an admin form? Is this something that the “Users” are entering on the front then? Is this something you’re doing in the admin?

    The easiest solution might be “Create Terms” setting for the taxonomy field, but this just let’s you create the term and set the name, it does not let you edit the description and will not let you edit anything else about the term.

  • Hi John, thanks for the reply!

    These fields would not be visible to the User. There’s only one Admin of the site and it would be up to them to fill out this Member taxonomy for each Post created. Basically, the only goal is to be able to sort Posts on the front-end by Members (similar to how Tags work).

    So far, I have the custom Taxonomy for Members added in the functions.php and it works great, I can add/edit those in the WP Dashboard (again, similar to Tags). I also added an ACF Taxonomy field to my Posts so that I can then choose any taxonomy Member that should be related to a Post.

    The final step here that I’m trying to solve is if a certain Member doesn’t exist yet, it would be ideal to be able to create that new Member from within the Post (rather than having to close the draft post, add the Member in the custom taxonomy area, then re-edit the post and select the member).

    The Create Terms setting does work perfect and I tried that but, like you pointed out, it only allowed me to create the new Member’s name. Is there any way possible that I can have the Create Terms setting also give me fields for slug and description?

  • How would I do this if I had to do it.

    I would create a true false field “Add New Member”

    Then I would create 3 fields Name, Slug and Description. These 3 fields would be conditional and only show if Add New Member is true, these fields would all be required.

    Then I would create an acf/save_post filter https://www.advancedcustomfields.com/resources/acf-save_post/. In this filter I would

    1. see if the add new member field was set
    2. if it is I would get the values from the other 3 fields
    3. I would use these values to create a new term https://codex.wordpress.org/Function_Reference/wp_insert_term
    4. Then I would add this term to the post https://codex.wordpress.org/Function_Reference/wp_set_post_terms
    5. And finally I would delete the values from the 3 ACF fields and update the add new member field to false

    But to be honest, I would not probably do this unless I had a client that insisted on it. I would tell them that before they add a new post for a member that does not exist that first they must add the member. Or I would tell them that they will need to go to the member when they are done with adding the post and add a description for the member after the fact. This is no different than adding a category, or (product category in woocommerce), the only thing that you can do is add the name and then you need to go to that category and add a description and other information if the site needs it later.

  • John, I can’t thank you enough. That’s exactly the info I was looking for. I sincerely appreciate your time and help.

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

The topic ‘Update Taxonomy With ACF Fields’ is closed to new replies.