正在处理目录列表,并拼凑出了我所能找到的最短查询。它似乎返回了列表ok(我认为),但foreach无法正确处理数组。有人能告诉我我做错了什么吗?
global $wpdb;
$site_blog_ids = array($wpdb->get_results($wpdb->prepare("SELECT blog_id FROM wp_blogs where blog_id > 1"))); // get all subsite blog ids
print_r( $site_blog_ids ); // checkem - output is "Array ( [0] => Array ( [0] => stdClass Object ( [blog_id] => 2 ) [1] => stdClass Object ( [blog_id] => 3 ) [2] => stdClass Object ( [blog_id] => 5 ) ) ) "
foreach( $site_blog_ids as $site_blog_id ) { //iterate through the ids
print_r( "siteid ".$site_blog_id ); // checkem - this just outputs "array array" ??
博客ID没有正确地通过foreach,它只是输出“array array”,而应该显示博客ID的列表。$site\\u blog\\u ids数组是否出现问题,或者我是否搞糟了其他事情?
谢谢你的帮助!大卫
五、 每MBoynes的帮助2人。修复了双数组,因为wpdb已经输出了一个数组。但foreach仍然无法输出$site\\u blog\\u id,将“$site\\u blog\\u id[0]更改为$site\\u blog\\u id”只输出数组中的第一个,然后停止。
global $wpdb;
$site_blog_ids = $wpdb->get_results($wpdb->prepare("SELECT blog_id FROM wp_blogs where blog_id > 1")); // get all subsite blog ids
print_r( $site_blog_ids ); // checkem - output is "Array ( [0] => stdClass Object ( [blog_id] => 2 ) [1] => stdClass Object ( [blog_id] => 3 ) [2] => stdClass Object ( [blog_id] => 5 ) ) "
foreach( $site_blog_ids AS $site_blog_id ) { //iterate through the ids
print_r( "siteid= ".$site_blog_id."</br>" ); // checkem - this shows no blog ids output at all ??
v.3世世代代全球工作版$wpdb$site\\u blog\\u id=$wpdb->获取结果($wpdb->准备(“从blog\\u id>1的wp\\u blogs中选择blog\\u id”);//获取所有子网站博客ID
print_r( $site_blog_ids ); // checkem - output is "Array ( [0] => stdClass Object ( [blog_id] => 2 ) [1] => stdClass Object ( [blog_id] => 3 ) [2] => stdClass Object ( [blog_id] => 5 ) ) "
foreach( $site_blog_ids AS $site_blog_id ) { //iterate through the ids
print_r( "siteid= ".$site_blog_id->blog_id."</br>" ); // checkem - anything in the loop that needs the blog ID value must pull it with the ->blog_id key.