get_post_meta()
is simply just a wrapper for get_metadata()
. If we look at the source or get_metadata()
, we will find that, if $key
is left empty, $single
is ignored because of the following lines of code which comes before $single
is applied
if ( ! $meta_key ) {
return $meta_cache;
}
So, in your usecase, $single
never gets to do it’s job.
The double key=>value pairs simply means that you have an array of values for that specific key, and the two values in the array are the same value. This is caused by a flaw somewhere in your code which is responsible for saving data to your custom field. You should go and search for that particular piece of code and sort that particular issue.
I cannot tell you which is the correct value and which not, that is something that you also cannot answer. As I said, you will need to sort your code responsible for saving your custom field data.
In the meantime, you can break out of your foreach loop to only get the first value from a custom field, but I do not recommend this as a solution, the solution will involve to sort how you save your custom field data
$postmeta = get_post_meta($resultid, '', true);
foreach ($postmeta as $meta_key => $v) {
foreach ($v as $kk => $meta_value) {
echo "$meta_key => $meta_value.\n";
break;
}
}