0

I am working on Wordpress. I use custom fields and one of the field category contains field type as taxonomy.

While inserting,the postmeta table contains this JSON value: a:1:{i:0;s:1:"5";}.

I need to get the value inside the " ".That is 5.

Olivier Pons
  • 15,363
  • 26
  • 117
  • 213
  • That is not valid JSON – StudioTime Nov 25 '17 at 08:46
  • That is actually PHP's [serialize](http://php.net/manual/en/function.serialize.php) data format; see also https://stackoverflow.com/q/8641889/1427878 Elvin85 is of course correct though, that you should stick to the functionality WP provides around this already. – CBroe Nov 25 '17 at 09:23

1 Answers1

2

Simply use native get_post_meta function which unserializes data itself:

echo get_post_meta(POST_ID_HERE,'post_meta_key_name_here',true)[0];

or this

$value=get_post_meta(POST_ID_HERE,'post_meta_key_name_here',true);
echo $value[0];
Elvin Haci
  • 3,503
  • 1
  • 17
  • 22