Make WordPress Core

Opened 17 years ago

Closed 12 years ago

Last modified 12 years ago

#11683 closed defect (bug) (fixed)

update_metadata() passes only the first meta_id

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

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 (3)

update-meta-ids.diff (1.6 KB ) - added by wonderboymusic 14 years ago.
11683.diff (1.9 KB ) - added by wonderboymusic 14 years ago.
11683.2.diff (4.7 KB ) - added by boonebgorges 12 years ago.

Download all attachments as: .zip

Change History (22)

#1 @scribu
17 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.

#2 @scribu
17 years ago

Related: #10905

#3 @scribu
17 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.

#4 @nacin
16 years ago

  • Milestone 3.03.1

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

#5 @nacin
16 years ago

  • Milestone Awaiting TriageFuture Release

#6 @wonderboymusic
14 years 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.

#7 @nacin
14 years ago

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

#8 @wonderboymusic
14 years ago

  • Milestone Future Release3.6

Patch refreshed against trunk like whoa - passes all Unit Tests

Last edited 14 years ago by wonderboymusic (previous) (diff)

#9 @ryan
13 years ago

  • Milestone 3.6Future Release

#10 @wonderboymusic
13 years ago

  • Milestone Future Release3.7

#11 @wonderboymusic
13 years ago

  • Milestone 3.73.8

#12 @wonderboymusic
13 years ago

  • Milestone 3.8Future Release

#13 @nacin
13 years ago

  • Component GeneralOptions and Meta

#14 @boonebgorges
12 years ago

  • Milestone Future Release4.1
  • Owner set to boonebgorges
  • Status newaccepted

11683.2.diff refreshes for latest trunk, and adds some Delightful unit tests.

#15 @boonebgorges
12 years ago

  • Resolutionfixed
  • Status acceptedclosed

In 30140:

Pass all updated meta IDs to filters in update_metadata().

Props wonderboymusic.
Fixes #11683.

#16 @DrewAPicture
12 years ago

  • Resolution fixed
  • Status closedreopened

The hook docs always need to directly precede the hook line so the parser can match them up.

#17 follow-up: @boonebgorges
12 years ago

You learn something new every day :) Thanks, DrewAPicture.

#18 @DrewAPicture
12 years ago

  • Resolutionfixed
  • Status reopenedclosed

In 30149:

Relocate hook docs so they directly precede the hook lines moved into foreach statements in [30140].

It's necessary for hook docs to directly precede hook lines so the parser can correctly match them up. This change relocates hook docs for update_{$meta_type}_meta, update_postmeta, updated_{$meta_type}_meta, and updated_postmeta.

Fixes #11683.

#19 in reply to: ↑ 17 @DrewAPicture
12 years ago

Replying to boonebgorges:

You learn something new every day :) Thanks, DrewAPicture.

Absolutely :-)

In the case of hooks, it's particularly important because phpDocumentor doesn't actually support parsing hook docs out of the box. Our implementation calls for the docs to directly precede hook lines so they don't get confused with function-level DocBlocks.

Note: See TracTickets for help on using tickets.