Open arthurshlain opened 6 months ago
Cannot save post terms submitted by taxonomy edit form with relationship bidirectional field.
To Reproduce
Create custom post type People and custom taxonomy Role for post type People.
People
Role
Add taxonomy field roles to People and enable save and load terms options.
roles
Add relationship field people_order for Role taxonomy.
people_order
Enable bidirectional relations between roles and people_order fields.
Create new People post and add a single value for roles field.
Edit role term by removing value from people_order field.
Expected behavior single-people.php
<p>Debug roles get_field: <?= json_encode(get_field('roles')) ?></p> <p>Debug roles get_the_terms: <?= json_encode(get_the_terms(get_the_ID(), 'role')) ?></p>
Debug roles get_field: false Debug roles get_the_terms: false
Actual behavior — the value still exists (loaded from wp object terms?)
Debug roles get_field: [55] Debug roles get_the_terms: [{"term_id":55,"name":"Director","slug":"director","term_group":0,"term_taxonomy_id":55,"taxonomy":"role","description":"","parent":0,"count":1,"filter":"raw"}]
Code acf-export.json
Version Information:
Additional context
The problem looks like solved when I comment this lines:
class-acf-field-taxonomy.php:381
// append $this->save_post_terms[ $taxonomy ] = array_merge( $old_term_ids, $term_ids ); // if called directly from frontend update_field(). -if ( ! did_action( 'acf/save_post' ) ) { $this->save_post( $post_id ); - return $value; -} return $value;
Looks like $this->save_post call is needed for this case.
$this->save_post
Cannot save post terms submitted by taxonomy edit form with relationship bidirectional field.
To Reproduce
Create custom post type
People
and custom taxonomyRole
for post typePeople
.Add taxonomy field
roles
toPeople
and enable save and load terms options.Add relationship field
people_order
forRole
taxonomy.Enable bidirectional relations between
roles
andpeople_order
fields.Create new![image](https://github.com/AdvancedCustomFields/acf/assets/2047645/de63d2f6-d32d-4051-83c8-9c05912c31c4)
People
post and add a single value forroles
field.Edit role term by removing value from
![image](https://github.com/AdvancedCustomFields/acf/assets/2047645/4d25ca12-5f32-48f1-974f-62d43badca0e)
people_order
field.Expected behavior single-people.php
Actual behavior — the value still exists (loaded from wp object terms?)
Code acf-export.json
Version Information:
Additional context
The problem looks like solved when I comment this lines:
class-acf-field-taxonomy.php:381
Looks like
$this->save_post
call is needed for this case.