从WP_USER_QUERY返回的类是什么样子的?

时间:2011-08-25 作者:leeand00

$wp_user_search = new WP_User_Query( array( \'role\' => \'author\' ) );
$author_list = $wp_user_search->get_results();

foreach($author_list as $author)
{
  // author properties?
}
你能告诉我哪些属性的文档方向吗$author

2 个回复
最合适的回答,由SO网友:marfarma 整理而成

具有SQL查询结果列名属性的行对象数组,即wp\\U users表中的指定字段,或者,如果字段等于“all\\u with\\u meta”,则为wp\\U用户对象数组。

字段值默认为“all”,这将返回wp_users table, 但可以通过传递指定字段的数组来覆盖,并按如下方式进行分析:

              if ( is_array( $qv[\'fields\'] ) ) {
                        $qv[\'fields\'] = array_unique( $qv[\'fields\'] );

                        $this->query_fields = array();
                        foreach ( $qv[\'fields\'] as $field )
                                $this->query_fields[] = $wpdb->users . \'.\' . esc_sql( $field );
                        $this->query_fields = implode( \',\', $this->query_fields );
                } elseif ( \'all\' == $qv[\'fields\'] ) {
                        $this->query_fields = "$wpdb->users.*";
                } else {
                        $this->query_fields = "$wpdb->users.ID";
                }
请参见中的查询函数WP_User_Query class definition - 如果“fields”是“all\\u with\\u meta”,则查询结果将替换为WP\\u用户对象

       function query() {
                global $wpdb;

                if ( is_array( $this->query_vars[\'fields\'] ) || \'all\' == $this->query_vars[\'fields\'] ) {
                        $this->results = $wpdb->get_results("SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit");
                } else {
                        $this->results = $wpdb->get_col("SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit");
                }

                if ( $this->query_vars[\'count_total\'] )
                        $this->total_users = $wpdb->get_var( apply_filters( \'found_users_query\', \'SELECT FOUND_ROWS()\' ) );

                if ( !$this->results )
                        return;

                if ( \'all_with_meta\' == $this->query_vars[\'fields\'] ) {
                        cache_users( $this->results );

                        $r = array();
                        foreach ( $this->results as $userid )
                                $r[ $userid ] = new WP_User( $userid, \'\', $this->query_vars[\'blog_id\'] );

                        $this->results = $r;
                }
        }
最后,这里记录了WP\\U用户对象:http://codex.wordpress.org/Class_Reference/WP_User

定义如下:http://core.trac.wordpress.org/browser/tags/3.2.1/wp-includes/capabilities.php

SO网友:kaiser

对foreach循环执行以下操作:

echo \'<pre>\';
foreach($author_list as $author)
{
    // author properties:
    // in detail:
    var_dump($author);
    // OR: overview:
    print_r($author);
}
echo \'</pre>\';

结束

相关推荐

是否在自定义帖子类型URL结构中添加%Author%?

我正在尝试重写WordPress的URL。。。具体而言,我有自定义的帖子类型,目前的工作方式如下:http://mydomain.com/videos/post-title/但我希望它位于:http://mydomain.com/videos/author-name/post-title/有没有办法做到这一点?