Home › Forums › Add-ons › Repeater Field › update_sub_field with taxonomy field › Reply To: update_sub_field with taxonomy field
Never mind! I fixed it by using the full field keys instead of slugs. Here’s the working code:
if ( $items->have_posts() ) {
$tax_var = get_terms('varieties_grown', 'hide_empty=0');
$tax_var_array = array();
foreach ( $tax_var as $tax ) {
$tax_var_array[] = array('term_id' => $tax->term_id, 'name' => $tax->name );
}
while( $items->have_posts() ) {
$items->the_post();
$post_id = get_the_ID();
if( have_rows('field_57d8b8c860d41')):
while ( have_rows( 'field_57d8b8c860d41' ) ) : the_row();
$variety = get_sub_field( 'field_57d8b8dc60d42' );
$key = array_search( $variety, array_column( $tax_var_array, 'name' ) );
if ( $key ) {
$term_id = $tax_var_array[$key]['term_id'];
update_sub_field('field_5894f9fbbad27', $term_id );
}
endwhile;
endif;
}
}
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.