WordPress Trac: Ticket #18702: get_post_custom and get_metadata inconsistent handling of arrays in meta valueshttps://core.trac.wordpress.org/ticket/18702
<p>
If get_post_custom is called before a post is fully saved, then it returns serialised values for any meta value that is an array. This appears to be due to it using a cached value and wp_cache_get returning serialised values. See lines 1519 in post.php
</p>
<p>
However if the meta value is retrieved later from the database the 'maybe unserialize' functions are applied, and the meta value array is returned as expected.
</p>
<p>
See lines 289 (a fairly recent nightly build) in meta.php, function get_metadata, applies these functions after the cache get.
</p>
<blockquote>
<p>
if ( isset($meta_cache[$meta_key]) ) {
</p>
<blockquote>
<p>
if ( $single )
</p>
<blockquote>
<p>
return maybe_unserialize( $meta_cache[$meta_key]<a class="missing changeset" title="No changeset 0 in the repository">[0]</a> );
</p>
</blockquote>
<p>
else
</p>
<blockquote>
<p>
return array_map('maybe_unserialize', $meta_cache[$meta_key]);
</p>
</blockquote>
</blockquote>
<p>
}
</p>
</blockquote>
<p>
Presumably get_post_custom should be consistent with get_metadata ?
</p>
<p>
I thought I saw some discussion elsewhere about arrays as metavalues and whether wp should 'handle' them. I think there are occasionally reasons why an array may make sense, although in principle agree that values should be held simply. (This also makes plugin integration easier on the whole). I picked this problem up where WPML (multlingual plugin) is attempting to copy meta data created by my events plugin. There are already many separate event data fields. The duration is stored as an array of weeks, days, hours, minutes, seconds. THis is fairly close to the way that the ical spec RFC5545 handles duration.
</p>
<p>
If it is 'policy' that arrays should NOT be held as metavalues, then let us highlight that in the CODEX, and I'lll figure out another way to store the duration.
</p>
en-usWordPress Trachttps://core.trac.wordpress.org/chrome/site/your_project_logo.pnghttps://core.trac.wordpress.org/ticket/18702
Trac 1.0.1scribuFri, 10 Feb 2012 22:12:44 GMTstatus changed; resolution set; milestone deletedhttps://core.trac.wordpress.org/ticket/18702#comment:1
https://core.trac.wordpress.org/ticket/18702#comment:1
<ul>
<li><strong>status</strong>
changed from <em>new</em> to <em>closed</em>
</li>
<li><strong>resolution</strong>
set to <em>duplicate</em>
</li>
<li><strong>milestone</strong>
<em>Awaiting Review</em> deleted
</li>
</ul>
<p>
<a class="closed ticket" href="https://core.trac.wordpress.org/ticket/19708" title="defect (bug): get_post_custom returns no data when cache addition suspended (closed: fixed)">#19708</a>
</p>
Ticket