WordPress.org

Make WordPress Core

Opened 4 years ago

Last modified 3 months ago

#11683 new defect (bug)

update_metadata() passes only the first meta_id

Reported by: scribu Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 2.9
Component: Options, Meta APIs Keywords: has-patch
Focuses: Cc:

Description

Code to reproduce:

function update_metadata_action_test($meta_id) {
	var_dump($meta_id);
}
add_action('update_post_meta', 'update_metadata_action_test');

add_metadata('post', 1, 'mykey', 'value1');
add_metadata('post', 1, 'mykey', 'value2');

update_metadata('post', 1, 'mykey', 'new value');

Expected result:

Array ( [0] => 101 [1] => 102 )

Actual result:

string(3) "101"

Attachments (2)

update-meta-ids.diff (1.6 KB) - added by wonderboymusic 20 months ago.
11683.diff (1.9 KB) - added by wonderboymusic 15 months ago.

Download all attachments as: .zip

Change History (15)

comment:1 scribu4 years ago

Two solutions:

  1. update_usermeta() only updates the first value that it finds
  1. update_usermeta() uses $wpdb->get_col() instead of $wpdb->get_var()

The first would create more severe backward compatibility issues than the second.

comment:2 scribu4 years ago

Related: #10905

comment:3 scribu4 years ago

Come to think of it, I have no ideea why $meta_id is passed at all (and as the first parameter at that). It's not accesible from anywhere else in the API.

comment:4 nacin4 years ago

  • Milestone changed from 3.0 to 3.1

Needs to be handled with #10905 I'd think.

comment:5 nacin3 years ago

  • Milestone changed from Awaiting Triage to Future Release

comment:6 wonderboymusic20 months ago

  • Keywords has-patch added

Added patch to get all meta_ids and call actions on all meta_ids individually, rather than breaking current behavior by passing arrays.

comment:7 nacin19 months ago

I've never really noticed that update_metadata() can update more than one row at a time.

wonderboymusic15 months ago

comment:8 wonderboymusic15 months ago

  • Milestone changed from Future Release to 3.6

Patch refreshed against trunk like whoa - passes all Unit Tests

Last edited 15 months ago by wonderboymusic (previous) (diff)

comment:9 ryan11 months ago

  • Milestone changed from 3.6 to Future Release

comment:10 wonderboymusic9 months ago

  • Milestone changed from Future Release to 3.7

comment:11 wonderboymusic7 months ago

  • Milestone changed from 3.7 to 3.8

comment:12 wonderboymusic5 months ago

  • Milestone changed from 3.8 to Future Release

comment:13 nacin3 months ago

  • Component changed from General to Options and Meta
Note: See TracTickets for help on using tickets.