如果您只想检查此函数返回的内容,只需在执行查询后包含此行:
var_dump($postsID);
如果您想对数据做某事,可以通过多种方式完成,但这取决于您到底想做什么;这个论坛有太多的选择。
更新:根据下面评论中的对话,您似乎想将结果的键 ( $postsID) 传递给 $wpdb->get_posts() 函数。
如果get_posts()只是将唯一 ID 作为参数,那么您必须执行以下操作:
// I'm assuming a simple key=>value pair in your array. Modify your code as needed
foreach($postsID as $id) {
$result = $wpdb->get_posts($id);
// code that will do "something" with $result
}
更新 2:因为$postsID看起来像这样: array(5) { [0]=> object(stdClass)#4015 (23) { ["ID"]=> string(3) "779" ["post_author"]=> string (2) "12" ["post_date"]=> 字符串(19) "2012-07-27 08:53:22" ["post_date_gmt"]=> 字符串(19) "2012-07-27 08:53: 22" ["post_content"]=> string(356) "Text" ["post_title"]=> string(58) "Продам 2-к квартиру Русское Поле" ["post_excerpt"]=> string(0) "" [ "post_status"]=> string(7) "publish" ["comment_status"]=> string(4) "open" ["ping_status"]=> string(4) "open" ["post_password"]=> string( 0)“”[“post_name”]=>字符串(162)“%d0%bf%d1%80%
您将需要从每个对象中获取 ID 并将其插入临时数组并将其传递给get_posts():
// $args = array( 'post__in' => array(779,772,768,761,716) );
$tempArr = array();
foreach ($postsID as $obj) {
$tempArr[] = $obj->id;
}
$args = array('post__in' => $tempArr);
$result = $wpdb->get_posts($args);