BP_Media_Album:: get_album_data (数组album_ids美元数组()

按照模板循环中的要求,将媒体id转换为媒体对象。

描述

参数

album_ids美元

数组(可选)媒体id数组。

默认值:数组()

返回

(数组)

文件:bp-media /类/ class-bp-media-album.php

Protected static function get_album_data($album_ids = array()) {global $wpdb;//如果没有媒体ID通过,则保释。If (empty($album_ids)){返回数组();} //获取BuddyPress。英国石油美元= buddypress ();数组$专辑= ();$uncached_ids = bp_get_non_cached_ids($album_ids, 'bp_media_album');//主要缓存。如果(!empty($uncached_ids)){//格式化相册ID以便在下面的查询中使用。 $uncached_ids_sql = implode( ',', wp_parse_id_list( $uncached_ids ) ); // Fetch data from album table, preserving order. $queried_adata = $wpdb->get_results( "SELECT * FROM {$bp->media->table_name_albums} WHERE id IN ({$uncached_ids_sql})"); // Put that data into the placeholders created earlier, // and add it to the cache. foreach ( (array) $queried_adata as $adata ) { wp_cache_set( $adata->id, $adata, 'bp_media_album' ); } } // Now fetch data from the cache. foreach ( $album_ids as $album_id ) { // Integer casting. $album = wp_cache_get( $album_id, 'bp_media_album' ); if ( ! empty( $album ) ) { $album->id = (int) $album->id; $album->user_id = (int) $album->user_id; $album->group_id = (int) $album->group_id; $album->media = bp_media_get( array( 'album_id' => $album->id, 'count_total' => true ) ); } $albums[] = $album; } // Then fetch user data. $user_query = new BP_User_Query( array( 'user_ids' => wp_list_pluck( $albums, 'user_id' ), 'populate_extras' => false, ) ); // Associated located user data with albums. foreach ( $albums as $a_index => $a_item ) { $a_user_id = intval( $a_item->user_id ); $a_user = isset( $user_query->results[ $a_user_id ] ) ? $user_query->results[ $a_user_id ] : ''; if ( !empty( $a_user ) ) { $albums[ $a_index ]->user_email = $a_user->user_email; $albums[ $a_index ]->user_nicename = $a_user->user_nicename; $albums[ $a_index ]->user_login = $a_user->user_login; $albums[ $a_index ]->display_name = $a_user->display_name; } } return $albums; }

更新日志

更新日志
版本 描述
BuddyBoss 1.0.0 介绍了。

问题吗?

我们总是很乐意帮助您解决代码或其他问题!搜索我们的开发人员文档联络支持,或与我们联系销售团队