Ad

WORDPRESS Database How To Return Meta Value From Database?

- 1 answer

I have in database this meta_key fw:ext:mm:io:primefeed and this meta_value a:5:{s:4:"type";s:6:"column";s:3:"row";a:0:{}s:6:"column";a:1:{s:14:"item_thumbnail";a:2:{s:13:"attachment_id";s:2:"11";s:3:"url";s:49:"//primefeed.loc/wp-content/uploads/2020/01/01.jpg";}}s:4:"item";a:0:{}s:7:"default";a:0:{}} How to return this meta value (link) //primefeed.loc/wp-content/uploads/2020/01/01.jpg ?

Ad

Answer

That's a PHP serialized array. You can see the structure using

print_r( unserialize( $value ) );

e.g. repl.it demo

Inside WordPress, you can do

$meta_value = get_post_meta($post_id, "fw:ext:mm:io:primefeed", true);
$url = $meta_value["column"]["item_thumbnail"]["url"];

where get_post_meta does both the database fetch and unserialize.

Ad
source: stackoverflow.com
Ad