Make WordPress Core

Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#19708 closed defect (bug) (fixed)

get_post_custom returns no data when cache addition suspended

Reported by: leewillis77's profile leewillis77 Owned by: duck_'s profile duck_
Milestone: 3.4 Priority: normal
Severity: normal Version: 3.3
Component: General Keywords: has-patch
Focuses: Cc:


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)

19708.diff (1.2 KB) - added by leewillis77 12 years ago.
Proposed patch
19708-2.diff (1.2 KB) - added by leewillis77 12 years ago.
Revised patch attached - correctly deals with a false returned from update_postmeta_cache().
19708.3.diff (1.1 KB) - added by duck_ 12 years ago.

Download all attachments as: .zip

Change History (11)

12 years ago

Proposed patch

12 years ago

Revised patch attached - correctly deals with a false returned from update_postmeta_cache().

#1 @leewillis77
12 years ago

  • Keywords has-patch added

#2 @ryan
12 years ago

  • Milestone changed from Awaiting Review to 3.4

This could also be a problem during imports.

#3 @leewillis77
12 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.

12 years ago

#4 @duck_
12 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 ''.

#5 @leewillis77
12 years ago

Looks good, and works for me ...


#6 @duck_
12 years ago

  • Owner set to duck_
  • Resolution set to fixed
  • Status changed from new to closed

In [19906]:

Make get_post_custom() a wrapper of get_post_meta() so that it works when cache addition is suspended and to simplify it.

Props leewillis77 for the initial patch. Fixes #19708.

#7 @scribu
12 years ago

3 birds with one stone: #15483 #18702

#8 @scribu
12 years ago

Related: #19882

Note: See TracTickets for help on using tickets.