This is what I’m doing:
$content = array(get_post_meta($postId, 'content'));
$media = array(get_post_meta($postId, 'media'));
$yt = array(get_post_meta($postId, 'youtube'));
$max = max(count($content), count($media), count($yt));
$combined = [];
for($i = 0; $i <= $max; $i++) {
if(isset($content[$i])) {
$combined[] = ["type" => "content", "value" => $content[$i]];
}
if(isset($media[$i])) {
$combined[] = ["type" => "media", "value" => $media[$i]];
}
if(isset($yt[$i])) {
$combined[] = ["type" => "youtube", "value" => $yt[$i]];
}
}
foreach ($combined as $key => $val) {
echo '<li>'.$val['value'].'</li>';
}
The result is:
Array
Array
Array
I’d expect:
media value
content value
youtube value
2
Answers
You are working with array of arrays because get_post_meta returns by default an array, unless the 3rd parameter
$single
is true.So try
or actually just
You realise that
creates
$content
as an array with a single value? (the value is whatever is returned by yourget_post_meta()
function)(and similarly for
$media
and$yt
)Each of these three will always have one and only one element.
Looking at the code that follows this, I’m not sure if this is what you intended.
$max
will always be one, for example, and$content[$i]
will always be the value returned by yourget_post_meta()
function – based on the result shown, presumably an array