I'm wondering how to display all the network sites in WP Multisite by displaying site description instead of site name. Below is the code provided by the expert in WP in this community. It's now displaying site name. What code should I change in order to make the list displaying all the sites with site description?
function wpse365255_print_sites() {
$args = array(
'number' => 10000, // if you've got more than 10,000 sites,
//you can increase this
'public' => 1,
'spam' => 0,
'deleted' => 0,
'archived' => 0,
'site__not_in' => array( 1, 2 ),
// this will exclude sites with ID 1 and 2
);
$sites = get_sites( $args ); // will return an array of WP_Site objects
$list = '';
foreach ( $sites as $site ) {
$details = get_blog_details( $site->blog_id );
if ( ! empty( $details ) ) {
$list .= '<li>';
$list .= '<a href="' . $details->siteurl . '">';
$list .= $details->blogname;
$list .= '</a>';
$list .= '</li>';
}
}
if ( ! empty( $list ) ) {
echo '<ul>' . $list . '</ul>';
}
}
I tried to change the blogname
to blogdescription
but the site description not showing up. I look forward to answers from the experts here. Thank you!
I'm wondering how to display all the network sites in WP Multisite by displaying site description instead of site name. Below is the code provided by the expert in WP in this community. It's now displaying site name. What code should I change in order to make the list displaying all the sites with site description?
function wpse365255_print_sites() {
$args = array(
'number' => 10000, // if you've got more than 10,000 sites,
//you can increase this
'public' => 1,
'spam' => 0,
'deleted' => 0,
'archived' => 0,
'site__not_in' => array( 1, 2 ),
// this will exclude sites with ID 1 and 2
);
$sites = get_sites( $args ); // will return an array of WP_Site objects
$list = '';
foreach ( $sites as $site ) {
$details = get_blog_details( $site->blog_id );
if ( ! empty( $details ) ) {
$list .= '<li>';
$list .= '<a href="' . $details->siteurl . '">';
$list .= $details->blogname;
$list .= '</a>';
$list .= '</li>';
}
}
if ( ! empty( $list ) ) {
echo '<ul>' . $list . '</ul>';
}
}
I tried to change the blogname
to blogdescription
but the site description not showing up. I look forward to answers from the experts here. Thank you!
1 Answer
Reset to default 2get_blog_option() return blog info by supplying blog id and blog option name. So you may try changing the blog name variable from
$details->blogname
to get_blog_option( $site->blog_id, 'blogdescription')
in the loop
Becauae get_blog_details() does not add the description from option to its output object. So it let is needed to manually fetch additional information.
By default, the get_blog_details() only returns the following details of the site
- blogname
- siteurl
- post_count
- home
$details->blogname
toget_blog_option( $site->blog_id, 'blogdescription')
– 西門 正 Code Guy - JingCodeGuy Commented May 8, 2020 at 10:03