最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to update custom taxonomy meta using ACF update_field() function or any other wordpress function

programmeradmin1浏览0评论

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.

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.

Share Improve this question edited Dec 31, 2015 at 15:24 Howdy_McGee 20.9k24 gold badges91 silver badges177 bronze badges asked Dec 31, 2015 at 8:27 Seen DruSeen Dru 791 gold badge1 silver badge8 bronze badges 1
  • Questions regarding 3rd Party Plugins ( such as Advanced Custom Fields ) are considered to be Off-Topic here. ACF has their own support. – Howdy_McGee Commented Dec 31, 2015 at 15:26
Add a comment  | 

3 Answers 3

Reset to default 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.

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 :)

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

发布评论

评论列表(0)

  1. 暂无评论