我正在尝试在我的multisite network
博客然而,当我尝试使用get_pages
它忽略了博客已通过switch_to_blog
.
$sites = wp_get_sites( array( \'limit\' => 1000 ) );
foreach ( $sites as $site ) {
$blog_id = intval( $site[\'blog_id\'] );
if ( $blog_id < 2 ) {
continue;
}
switch_to_blog( $blog_id );
$pages = get_pages( array(
\'sort_order\' => \'asc\',
\'sort_column\' => \'ID\',
\'post_type\' => \'page\',
\'post_status\' => \'publish\',
) );
echo \'Blog ID: \' . get_current_blog_id() . \' | Total Pages: \' . count ( $pages ) . \'<br>\';
// foreach( $pages as $page ) {
// echo \'Blog ID: \' . $blog_id . \' | Post ID: \' . $page->ID . \'<br>\';
// }
restore_current_blog();
}
输出:
Blog ID: 2 | Total Pages: 71
Blog ID: 3 | Total Pages: 71
Blog ID: 4 | Total Pages: 71
Blog ID: 5 | Total Pages: 71
Blog ID: 6 | Total Pages: 71
Blog ID: 7 | Total Pages: 71
Blog ID: 8 | Total Pages: 71
Blog ID: 9 | Total Pages: 71
Blog ID: 10 | Total Pages: 71
Blog ID: 11 | Total Pages: 71
Blog ID: 12 | Total Pages: 71
Blog ID: 13 | Total Pages: 71
Blog ID: 14 | Total Pages: 71
Blog ID: 15 | Total Pages: 71
Blog ID: 16 | Total Pages: 71
Blog ID: 17 | Total Pages: 71
Blog ID: 18 | Total Pages: 71
Blog ID: 19 | Total Pages: 71
Blog ID: 20 | Total Pages: 71
上面的脚本将var\\u转储相同的
$pages
通过整个循环,无论它切换到哪个博客。我到底做错了什么?有没有办法完成我想做的事情?