get_post_meta return empty string
Posted
by
Jean-philippe Emond
on Stack Overflow
See other posts from Stack Overflow
or by Jean-philippe Emond
Published on 2014-08-19T16:16:39Z
Indexed on
2014/08/19
16:20 UTC
Read the original article
Hit count: 230
I guest it is a little issues but
I running a SQL to get some post id.
$result = $wpdb->get_results("SELECT wppm.post_id FROM wp_postmeta wppm INNER JOIN wp_posts wpp ON wppm.post_id=wpp.ID WHERE wppm.meta_key LIKE 'activity'");
(count: 302)
After that, I get all id and I run get_post_meta like that:
foreach($result as $id){
$activity = get_post_meta($id);
var_dump($activity);
foreach($activity as $key=>$value){
if(is_array($value) && $key=="age"){
var_dump($value);
}
}
}
(var_dump result: string "")
samething if I run with:
$activity = get_post_meta($id,'activity',true);
Where we need to get a result.
What is wrong?
Thank you for your help!!!
[Bonus Question] If the "activity" meta_key as an array Value. and I get directly like:
$result = $wpdb->get_results("SELECT wppm.meta_value FROM wp_postmeta wppm INNER JOIN wp_posts wpp ON wppm.post_id=wpp.ID WHERE wppm.meta_key LIKE 'activity'");
How I parse it?
Thanks again!
© Stack Overflow or respective owner