AdvancedCustomFields / AdvancedCustomFields/acf
The save_post_terms array values assigned but not saved for bidirectional values
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 945
- Forks
- 197
- PR merge metrics
- No merged PRs in 30d
Description
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.
Add taxonomy field roles to People and enable save and load terms options.
Add relationship field people_order for Role taxonomy.
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:
- WordPress Version 6.4.2
- PHP Version 8.1.2
- ACF Version ACF PRO 6.2.4
- Browser Chrome 120
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.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with class-acf-field-taxonomy.php around line 381 and follow how save_post_terms is handled when the taxonomy edit form updates the bidirectional relationship. Reproduce the People and Role setup from the issue, then verify that removing people_order clears both get_field('roles') and get_the_terms(). Done means the removed term is no longer saved or returned.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100