如何从wp网络的所有blog_id获取所有用户的The_author_meta('description')

时间:2013-10-13 11:10:58

标签: php wordpress foreach author

我试着这个获得作者的昵称:

    <h2>Articoli di: <span class="nome-autore"><?php global $wpdb, $blog_id;

$blogs = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM wp_blogs ORDER BY blog_id" ) );

foreach ($blogs as $blog){

if(wp_count_posts == 0){
    switch_to_blog($blog->blog_id);} else 
    if(wp_count_posts > 0){

    echo $curauth->nickname; }?></span></h2>

然后是元描述:

<p>Su di me: <span class="descrizione-autore">"<?php global $wpdb, $blog_id; $blogs = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM wp_blogs ORDER BY blog_id" ) );

foreach ($blogs as $blog){

if(wp_count_posts == 0){
    switch_to_blog($blog->blog_id);} else 
    if(wp_count_posts > 0){

    echo  the_author_meta( 'description' ); ?>"</span></p>

但问题是它显示了每个blog_id的所有昵称和描述。如何只选择一个值进行显示?

1 个答案:

答案 0 :(得分:0)

您需要首先收集所有博客ID然后循环它们。这是未经测试的

global $wpdb, $blog_id;

$blogs = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM wp_blogs ORDER BY blog_id" ) );

foreach ($blogs as $blog){

    switch_to_blog($blog->blog_id);

    $blogusers = get_users('orderby=nicename');

    foreach ($blogusers as $user) {
        echo '<li>' . $user->description . '</li>';
    }

    restore_current_blog();
}