Home › Forums › ACF PRO › Save User ID as Term Meta › Reply To: Save User ID as Term Meta
Hey @benheath
It would be great if there was a hook we can tap into each time a new Taxonomy was created. That process is being done with JavaScript, and I don’t know of any hook at that step. But that would present another issue… the User could end up not using the Term in the end… so that would need more thinking anyway.
With that said… I asked myself these questions..
I know it would be easy to run add_term_meta() on ‘save’… that’s not an issue.
What I would like to know is…
1) How would we know if a term has been newly added by this User?
2) Can we assume that if ‘term_author_id’ is NOT set, it’s new? Probably.
So… after a Post is Published/Saved… even within the wp_insert_post hook, we can:
Iterate through all terms attached to *that* post. Look for ones that don’t have term_author_id set, and assume (safely) that the current User came up with that term.. then we run run add_term_meta() function.
I don’t have the exact code for you… but do it bit by bit, and use var_dump each step of the way to see if you are getting what you are supposed to.
Here’s a good reference: https://www.smashingmagazine.com/2015/12/how-to-use-term-meta-data-in-wordpress/
Also… there are heaps of functions specific to Terms/Taxonomies for WordPress… get_terms and get_the_terms seem to be good choices here.
Sorry that I couldn’t be more help, but this should get you moving along further I hope!
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!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.