#19708 closed defect (bug) (fixed)
get_post_custom returns no data when cache addition suspended
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | 3.4 |
| Component: | General | Version: | 3.3 |
| Severity: | normal | Keywords: | has-patch |
| 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)
leewillis77 — 17 months ago
leewillis77 — 17 months ago
Revised patch attached - correctly deals with a false returned from update_postmeta_cache().
comment:1
leewillis77 — 16 months ago
- Keywords has-patch added
- Milestone changed from Awaiting Review to 3.4
This could also be a problem during imports.
comment:3
leewillis77 — 16 months 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.
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 ''.
comment:5
leewillis77 — 16 months ago
Looks good, and works for me ...
Thanks
- Owner set to duck_
- Resolution set to fixed
- Status changed from new to closed
In [19906]:

Proposed patch