1

I'm trying to update the Advanced Custom Fields meta value associated with a custom taxonomy term

$term_status = wp_update_term( $rate_id, 'rate', $term_data );

$term_id = $term_status['term_taxonomy_id'];

update_field( 'field_56829855eebc9',$rate_daily,$term_id );

However, I'm not getting the field updated. I have tried the field name instead of the field key too.

1

3 Answers 3

6

I figured it out somehow..

Syntax of update_field():

update_field($field_key, $value, $post_id)

MY MISTAKE: I was using the wrong parameter for the $post_id which i thought was the Term Id of the custom taxonomy term.

CORRECT USAGE: rather than using term id ($term_id in my question), one should use a string with the taxonomy preppended to the $term_id

ie $post_id = $taxonomy.'_'.$term_id

for eg: if your custom taxonomy is foo and the term id is 123

then : $post_id = foo_123

Hope this is helpful for someone.

This is the first time I'm asking/answering a question here.

3
  • 1
    Thanks so much! Just want to point out a typo as well. You forgot the underscore: it's $term_name . '_' . $term_id
    – jgthms
    Apr 6, 2018 at 12:41
  • note: this should be the name of the taxonomy followed by the term id
    – eballeste
    Jun 20, 2019 at 23:21
  • @eballeste thank you for this. Iwas having the same issue, landing me on this post, and you caused me to slow down and review all the pieces of my issue ... only to find that I had incorrectly typed the name of my own custom taxonomy. Feb 5, 2023 at 13:20
0

Only this worked for me:

update_term_meta($term_id, $field['name'], $value);

In my case i have an "author" taxonomy with a custom field called "institution", so i did:

$my_author_taxonomy = get_term_by( "name", $author_taxonomy_name, 'author' );   
update_term_meta($my_author_taxonomy->term_id, "institution", $Institution);

I hope it will help someone :)

0

I had success using wp_set_object_terms, as suggested by the official ACF support.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.