Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The save_post_terms array values assigned but not saved for bidirectional values #891

Open
arthurshlain opened this issue Jan 1, 2024 · 0 comments

Comments

@arthurshlain
Copy link

arthurshlain commented Jan 1, 2024

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.

image

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.
image

Edit role term by removing value from people_order field.
image
image

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"}]

image

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant