wordpress-seo icon indicating copy to clipboard operation
wordpress-seo copied to clipboard

Taxonomy meta set_value() overwrites existing meta values

Open o-samaras opened this issue 5 months ago • 0 comments

  • [x] I've read and understood the contribution guidelines.
  • [x] I've searched for any related issues and avoided creating a duplicate issue.

Please give us a description of what happened

When using WPSEO_Taxonomy_Meta::set_value() any existing taxonomy meta values are overwritten.

To Reproduce

Step-by-step reproduction instructions

  1. On a clean installation, go to Posts --> Categories and edit the Uncategorized term.
  2. Fill in the Yoast SEO attributes (focus keyword, title, description, canonical URL etc.)
  3. Create a MU Plugin (or normal plugin and activate it) and place the code from below. This will programmatically update the term edited above and set the focus keyword to "uncategorized" during the next page load.
  4. Refresh the page (this will trigger the code from above step).
  5. Go to Posts --> Categories --> Edit Uncategorized and check Yoast

Expected results

  1. Only the selected field (focus keyword in above example) is updated.

Actual results

  1. Only the update field is persisted, and all other previous values are removed.

Screenshots, screen recording, code snippet

If possible, please provide a screenshot, a screen recording or a code snippet which demonstrates the bug.

Code for the plugin to reproduce the issue

add_action('wp_loaded', function () {
    WPSEO_Taxonomy_Meta::set_value(
        1,
        'category',
        'focuskw',
        'uncategorized'
    );
});

Screenshot of DB entry after the initial edit via the Yoast metabox. image

Screenshot of DB entry after the WPSEO_Taxonomy_Meta::set_value() is called: image

Technical info

  • If relevant, which editor is affected (or editors):
  • [ ] Block Editor
  • [ ] Gutenberg Editor
  • [ ] Elementor Editor
  • [ ] Classic Editor
  • [ ] Other:
  • Which browser is affected (or browsers):
  • [ ] Chrome
  • [ ] Firefox
  • [ ] Safari
  • [ ] Other:

Used versions

  • Device you are using:
  • Operating system:
  • PHP version: 8.1
  • WordPress version: 6.2.2
  • WordPress Theme: Twentwy Twentyfour
  • Yoast SEO version: 23.4
  • Gutenberg plugin version:
  • Elementor plugin version:
  • Classic Editor plugin version:
  • Relevant plugins in case of a bug:

o-samaras avatar Sep 23 '24 13:09 o-samaras