我试图更新一个表格,在一个网站,使一个下拉列表的所有网站可以注册在一个可湿性粉剂网络网站。它是按ID订购的,但我需要把它改为字母顺序。它所做的也是,有一些代码,允许一些网站不显示在列表中,如果标记为排除。我还看到它使用的代码是从wp4.6开始降级的,所以它需要进行一般的更新。
问题是,我看到,我不知道如何做到这一点,和原来的编码器已经消失了,我的知识是有限的。
有人能帮我更新这段代码以达到当前的标准并按字母顺序排序吗?
10000, );
$TheBlogs = wp_get_sites($args);
foreach($TheBlogs as $blog){
$theBlog = get_blog_details( $blog['blogname'], true );
if(get_site_option('msregister_blog1_id')!=$blog['blogname'] && get_site_option('msregister_exclude_'.$blog['blogname'])!='yes'){
echo ''.$theBlog->blogname.'';
}
}
?>发布于 2018-03-19 05:30:11
因此,由于wp_get_sites()的弃用而需要更新的主要更改是将其更改为get_sites()。当使用get_sites()时,$TheBlogs将是WP_Site对象的数组,而不是数组的数组。这意味着要获取站点的详细信息,而不是使用get_blog_details(),您可以使用$blog->__get( 'blogname' )。
另一部分,按字母顺序排序,将需要对结果数组进行排序,因为get_sites()似乎没有按blogname排序的参数。
// Get blogs with get_sites(), which uses 'number' instead of 'limit'.
$blogs = get_sites( ['number' => 1000] );
// Sort blogs alphabetically.
uasort(
$blogs,
function( $a, $b ) {
// Compare site blog names alphabetically for sorting purposes.
return strcmp( $a->__get( 'blogname' ), $b->__get( 'blogname' ) );
}
);
foreach ( $blogs as $blog ) {
// Store blog name in variable for later use.
$blogname = $blog->__get( 'blogname' );
// Check blog is not excluded.
if (
get_site_option( 'msregister_blog1_id' ) != $blogname &&
get_site_option( 'msregister_exclude_' . $blogname ) != 'yes'
) {
// Output option tag, escaping the blog name as appropriate.
printf(
'%s',
esc_attr( $blogname ),
esc_html( $blogname )
);
}
}https://wordpress.stackexchange.com/questions/298207
复制相似问题