#19708 closed defect (bug) (fixed)
get_post_custom returns no data when cache addition suspended
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 3.4 | Priority: | normal |
Severity: | normal | Version: | 3.3 |
Component: | General | Keywords: | has-patch |
Focuses: | Cc: |
Description
If cache addition is suspended via wp_suspend_cache_addition(true) then get_post_custom($foo) returns no data.
The cause is that in optimising for performance inside get_post_custom an assumption that cache values can be stored and subsequently retrieved. As a result, the return value is generated by calling wp_cache_get() which will fail to return anything since cache additions are suspended.
The values required are however already being generated and passed back into get_post_custom. The attached patch returns these without relying on a call to wp_cache_get.
Attachments (3)
Change History (11)
@
13 years ago
Revised patch attached - correctly deals with a false returned from update_postmeta_cache().
#2
@
13 years ago
- Milestone changed from Awaiting Review to 3.4
This could also be a problem during imports.
#3
@
13 years ago
As with #19690, the use case that caused me to stumble on this is in plugins that wish to iterate over all (or a potentially large number of) posts. The specific use case that caused this is generating an XML feed of product information from e-Commerce stores for Google Merchant Centre.
In this context you want to iterate over all posts of a specific type, but there's no specific advantage in adding those posts (Or related information) to the cache - hence the use of wp_suspend_cache_addition(true).
Unfortunately as soon as cache additions are suspended, get_post_custom fails to return data for posts that do have custom info set.
#4
@
13 years ago
Nice catch.
I have attached 19708.3.diff which also simplifies get_post_custom() by essentially making it a wrapper for get_post_meta() with $meta_key set to ''
.
Proposed patch