get_post_meta返回空字符串

时间:2014-08-19 16:16:40

标签: mysql wordpress

我猜它有点问题但是

我运行SQL来获取一些帖子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)

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" }
    ..........

在那之后,我得到了所有的id,我就这样运行get_post_meta:

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 "")

如果我跑的话也一样:

$activity = get_post_meta($id,'activity',true);

我们需要获得结果。

有什么问题?

感谢您的帮助!!!

[奖金问题] 如果"活动" meta_key作为数组值。我直接得到了:

$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'");

我如何解析它?

再次感谢!

0 个答案:

没有答案