WordPress.org

Make WordPress Core

Opened 3 years ago

Last modified 3 years ago

#30995 new enhancement

Pass meta_id when retrieving multiple metas

Reported by: GregLone Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 2.9
Component: Options, Meta APIs Keywords: needs-patch needs-unit-tests
Focuses: Cc:

Description

Hello.

In some (edge?) cases we would need a unique identifier when we retrieve metas. For example, get_post_custom_values( '_yolo', $post->ID ) will return:

Array
(
    [0] => foo
    [1] => bar
)

while the following, with the meta_id as array key, would be helpful imho:

Array
(
    [1022] => foo
    [1029] => bar
)

The modification is trivial in update_meta_cache(), and some other functions would only need something like metas[0] => reset( metas ).

Change History (3)

#1 @sc0ttkclark
3 years ago

I like the idea behind this, based on your purpose.

#2 follow-up: @GregLone
3 years ago

In the same time, all the *_metadata_by_mid() would benefit of the cache.

#3 in reply to: ↑ 2 @boonebgorges
3 years ago

  • Keywords needs-patch needs-unit-tests added
  • Milestone changed from Awaiting Review to Future Release

Replying to GregLone:

In the same time, all the *_metadata_by_mid() would benefit of the cache.

IMO, this makes the proposal worth pursuing. It'd be nice to see improved unit tests around cache invalidation for update_metadata(), update_metadata_by_id(), and their delete_ equivalents as part of this improvement.

I'm somewhat concerned about backward compatibility. In the same way that core sometimes references $metas[0], it's possible that there are plugins doing the same thing. Does anyone have a good idea of how to gauge this impact? My google-fu is failing me :)

Note: See TracTickets for help on using tickets.