get_post_meta return empty string

I guess its a little issues but

I running a SQL to get some post id.

Read More
$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)

Result of the Var_dump:

array(302) { 
    [0]=> object(stdClass)#5084 (1) { ["post_id"]=> string(4) "8840" }
    [1]=> object(stdClass)#5134 (1) { ["post_id"]=> string(4) "8841" }
    [2]=> object(stdClass)#5130 (1) { ["post_id"]=> string(4) "8842" } 
    [3]=> object(stdClass)#5152 (1) { ["post_id"]=> string(4) "8843" } 
    [4]=> object(stdClass)#5123 (1) { ["post_id"]=> string(4) "8844" } 
    [5]=> object(stdClass)#5132 (1) { ["post_id"]=> string(4) "8845" } 
    [6]=> object(stdClass)#5141 (1) { ["post_id"]=> string(4) "8846" }
    [7]=> object(stdClass)#5133 (1) { ["post_id"]=> string(4) "8847" } 
    [8]=> object(stdClass)#5131 (1) { ["post_id"]=> string(4) "8848" }
    ..........

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!

Related posts

Leave a Reply