wordpress how to retrieve a single custom field value from a custom field array

1.7k views Asked by At

I have a custom fields that is actually an array.

I would like to get one single field value from this array.

When I do: $meta = get_post_meta( get_the_ID(), 'my_fields_array'); and then var_dump($meta); // debugging I can see the array

How can I get one single value from this array?

2

There are 2 answers

0
user3590313 On BEST ANSWER

I think I've found a solution: the issue is that the custom fields values I need are actually serialized into a string. So if I unserialize them I'm able to get what I need:

$meta= get_post_meta( $post->ID, 'custom_field_array', true );
$myvalues = unserialize( $meta );
echo $myvalues[my_value];

It works

1
Frosty On

If you just want to get a value from an array instead of using

var_dump

Just echo out the value that you need, starting from 0 e.g.

<?php 
$meta = array('Best','Worst','Stuff');

echo $meta[1];
 ?>

In my case echo $meta[1] = Worst

now do the same for your code,if you just want to see the value that is