#25511 closed enhancement (fixed)
get_post_meta does not always return data in the same order
Reported by: | mattheu | Owned by: | wonderboymusic |
---|---|---|---|
Milestone: | 3.8 | Priority: | normal |
Severity: | normal | Version: | 3.8 |
Component: | General | Keywords: | has-patch commit |
Focuses: | Cc: |
Description
get_post_meta does not always return data in the same order when returning an array of all meta values for a given key.
Expected outcome: I expect the order to remain the same every time this data is retrieved.
This usually returns data in the correct order but it is not guaranteed as the SQL query in the update_meta_cache function does not explicitly order by anything.
I propose that meta data should be explicitly ordered by meta_id.
I have a patch if this is considered a but
Attachments (4)
Change History (19)
#2
@
11 years ago
Hi @mattheu, you mentioned having a patch in the ticket description. Can you upload this patch now so that we can see what kind of approach you had in mind?
#5
@
11 years ago
I've updated the patch to use a ternary operator for the orderby_column
to be more consistent with the rest of the code base. Thanks @jeremyfelt
#6
@
11 years ago
- Milestone changed from Awaiting Review to 3.8
- Type changed from defect (bug) to enhancement
#12
@
11 years ago
- Keywords commit added
25511.4.diff ditches the unnecessary $wpdb->prepare
call which was passing a variable to a SQL statement with no replacement tokens
Use case:
I have a plugin that allows users to add custom fields to the post edit screen. It is possible to create a field and add multiple values which are then stored as separate post meta entries using a single key. Users expect that the order of this data will be preserved.
When this data is saved, all previously stored data is deleted and then added again in the order it was submitted to ensure that the meta_id order corresponds to the desired order of the data.