我从postmeta获取post_id为:
$post_id = $wpdb->get_results("SELECT post_id FROM $wpdb->postmeta WHERE (meta_key = 'mfn-post-link1' AND meta_value = '". $from ."')");
当我尝试print_r($post_id); 我有这样的数组:
print_r($post_id);
Array ( [0] => stdClass Object ( [post_id] => 140 ) [1] => stdClass Object ( [post_id] => 141 ) [2] => stdClass Object ( [post_id] => 142 ) )
而且我不知道如何遍历它,如何获得这样的数组
Array ( [0] => 140 [1] => 141 [2] => 142 )
知道我该怎么做吗?
最简单的方法是对对象进行JSON编码,然后将其解码回数组:
$array = json_decode(json_encode($object), true);
或者,如果您愿意,也可以手动遍历对象:
foreach ($object as $value) $array[] = $value->post_id;