BP_Activity_Activity: get (数组args美元=数组())

获取由参数指定的活动项。

描述

另见

参数

args美元

(数组)(可选)参数数组。所有项目都是可选的。

  • “页面”
    (国际)获取结果的哪一页。使用page=1而不使用per_page将不会导致分页。默认值:1。
  • “每页”
    (int|bool)每页的结果数。默认值:25。
  • “马克斯”
    (int|bool)返回的最大结果数。默认值:false(无限)。
  • “字段”
    (字符串)要返回的活动字段。传递“ID”以仅获取活动ID。““全部”返回完整的活动对象。
  • “排序”
    (字符串)ASC或DESC,默认为'DESC'。
  • “订购人”
    (字符串)按列对结果排序。
  • “排除”
    (数组)要排除的活动ID数组。默认值:false。
  • “在”
    (数组)通过(IN)限制查询的id数组。默认值:false。
  • “meta_query”
    (数组)meta_query条件数组。看到WP_Meta_Query:查询。
  • “date_query”
    (数组)日期查询条件数组。请参阅WP_Date_查询的第一个参数::_构造()。
  • “筛选查询”
    (数组)高级查询条件数组。看见BP_Activity_Query: __construct ().
  • “范围”
    (字符串|数组)预先确定的活动参数集。
  • “过滤”
    (数组)看见BP_Activity_Activity: get_filter_sql ().
  • “搜索术语”
    (字符串)按搜索词限制结果。默认值:false。
  • “隐私”
    (字符串)用隐私来限制结果。默认值:公众。
  • “display_comments”
    (布尔)是否包含活动注释。默认值:false。
  • “显示隐藏”
    (布尔)是否显示标记为hide_sitewide的项目。默认值:false。
  • “垃圾邮件”
    (字符串)垃圾邮件状态。默认值:“仅限火腿”。
  • “update_meta_cache”
    (布尔)是否预取查询到的活动项的元数据。默认值:真的。
  • “count_total”
    (字符串| bool)如果为true,将运行一个附加的DB查询来计算查询的活动项总数。默认值:false。

默认值:数组()

回来

(数组)返回的数组有两个键:- 'total'是已定位活动的计数- 'activities'是已定位活动的数组

文件:bp活动/classes/class-bp-activity-activity.php

公共静态函数get($args=array()){global$wpdb;//与传递参数的旧方法的向后兼容性。如果(!is_array($args)| | func_num_args()>1){不推荐使用的_参数(u方法,'1.6',sprintf(__(“传递给%1$s的参数应在关联数组中。有关详细信息,请参阅%2$s处的内联文档。”、“buddyboss”)、_方法、_文件);$old_参数\u keys=array(0=>'max',1=>'page',2=>'per_page',3=>'sort',4=>'search_terms',5=>'filter',6=>'display_comments',7=>'show_hidden',8=>'exclude',9=>'in',10=>'spam');$args=bp_核心_解析_数组($old_args密钥,func_get_args())}$bp=buddypress();$r=wp解析_args($args,array('page'=>1,//当前页面。'per_page'=>25,//每页的活动项目。'max'=>false,//要返回的最大项目数。'fields'=>'all',//要包含的字段。'sort'=>'DESC',//ASC或DESC.'order_by'=>'date_recorded',//要排序的列。'exclude'=>false,//要排除的ID数组。'in'=>false,//要限制的ID数组按(IN)查询。'meta\u query'=>false,//按activitymeta筛选。'date\u query'=>false,//按日期筛选。'Filter\u query'=>false,//高级筛选-请参阅BP\u Activity\u query。'Filter'=>false,//请参阅self::get\u Filter\u sql()“'scope'=>false,//预设活动参数。'search\u terms'=>false,//要搜索的术语。'privacy'=>false,//public,loggedin,onlyme,friends,media。'display\u comments'=>false,//是否包含活动注释。'show\u hidden'=>false,//显示标记为hide\u sitewead的项目。'spam'=>'ham\u only',//垃圾邮件状态。//更新元缓存。”'=>true,//是否更新元缓存。'count_-total'=>false,//是否使用count_-total。);//选择条件。$Select_-sql=“Select DISTINCT a.id”;$from_-sql=“from{$bp->activity->table_-name}a;$join_-sql='''.//Where条件。$Where_-conditions=array();//排除的类型。$Excluded_-typed=array();//范围优先。如果(!empty($r['Scope']){$Scope_query=self::get_Scope_query_sql($r['Scope'],$r);//如果找到匹配项,请添加我们的sql条件。如果(!empty($Scope_query['sql']){$where_条件['Scope_query sql']=$Scope_query['sql']}//如果需要,请覆盖一些参数。如果(!empty(!empty($Scope_query Override['sql']){$r=array\u replace\u recursive($r,$scope\u query['override']);}//高级筛选。}elseif(!empty($r['filter\u query']){$filter\u query=new BP\u Activity\u query($r['filter\u query']);$sql=$filter\u query->get\u sql();if(!empty($sql)){$where\u条件['filter\u query][sql']=$sql;}//常规筛选。if($r['filter['filter']&&&$filter\u sql=BP\u Activity\u Activity::get\u filter\u sql('r['filter']){$where\u conditions['filter\u sql']=$filter\u sql;}Spam.if('ham\u only'==r['Spam']){$where\u conditions['Spam\u']='a.is\u-Spam=0'.}elseif('Spam\u-only'=$r['Spam']){$where\u-conditions['Spam\u['Spam']='a.is\u=1]搜索术语('r}){$search_terms_like='%'.bp_esc_like($r['search_terms'])。%'$where_conditions['search_sql']=$wpdb->prepare('a.content like%s',$search_terms_like);/***筛选是否包含用户的搜索参数。**@自BuddyPress 3.0.0**@param bool$value是否包含用户搜索。默认值为false.*/if(应用_过滤器('bp_activity_get_include_user_search',false)){$user_search=get_user_by('slug',$r['search_terms']);if(false!=$user_search){$user_id=$user_search->id;$where_条件['search_sql']。=$wpdb->prepare('OR.user_id=%d',$user_id)}}//Sorting.//Sorting.$sort=$r['sort'];if($sort=$sort='ast''{$sort='DESC';}开关($r['order\u by']){case'id':case'user\u id':case'component':case'type':case'action':case'content':case'primary\u link':case'secondary\u item\u id':case'date\u recorded':case'hide\u sitew':case'mpt\u left':case'mpt\u right':case'is\u spam':break;default:$r['order\u by']='date_recorded';break;}$order_by='a..$r['order_by'];//隐藏隐藏的项目?如果(!$r['show_Hidden']){$where_条件['Hidden_sql']=“a.Hide_sitewide=0”;}//排除指定的项目。如果(!empty($r['Exclude']){$Exclude=内爆(',,wp_解析id_列表($r['Exclude']);$where_条件['Exclude']=“a.id不在({$exclude});}//要限制查询的特定id。如果(!empty($r['in']){$in=introde(',',,wp_parse_id_list($r['in']);$where_条件['in']=“a.id in({$in})”;}//过滤活动的隐私如果(!empty($r['privacy']){$privacy=“”,“,”,$privacy=“”,$r['privacy'])。”$where_conditions['privacy']=“a.privacy IN({$privacy})”;}//将元查询处理成SQL。$meta_query_SQL=self::get_meta_query_SQL($r['meta_query']);if(!empty($meta query_SQL['join']){$join_SQL.=$meta query SQL['join']}if(!empty($meta_query_sql['where'] ) ) { $where_conditions[] = $meta_query_sql['where']; } // Process date_query into SQL. $date_query_sql = self::get_date_query_sql( $r['date_query'] ); if ( ! empty( $date_query_sql ) ) { $where_conditions['date'] = $date_query_sql; } // Alter the query based on whether we want to show activity item // comments in the stream like normal comments or threaded below // the activity. if ( false === $r['display_comments'] || 'threaded' === $r['display_comments'] ) { $excluded_types[] = 'activity_comment'; } // Exclude 'last_activity' items unless the 'action' filter has // been explicitly set. if ( empty( $r['filter']['object'] ) ) { $excluded_types[] = 'last_activity'; } // Build the excluded type sql part. if ( ! empty( $excluded_types ) ) { $not_in = "'" . implode( "', '", esc_sql( $excluded_types ) ) . "'"; $where_conditions['excluded_types'] = "a.type NOT IN ({$not_in})"; } /** * Filters the MySQL WHERE conditions for the Activity items get method. * * @since BuddyPress 1.9.0 * * @param array $where_conditions Current conditions for MySQL WHERE statement. * @param array $r Parsed arguments passed into method. * @param string $select_sql Current SELECT MySQL statement at point of execution. * @param string $from_sql Current FROM MySQL statement at point of execution. * @param string $join_sql Current INNER JOIN MySQL statement at point of execution. */ $where_conditions = apply_filters( 'bp_activity_get_where_conditions', $where_conditions, $r, $select_sql, $from_sql, $join_sql ); // Join the where conditions together. $where_sql = 'WHERE ' . join( ' AND ', $where_conditions ); /** * Filter the MySQL JOIN clause for the main activity query. * * @since BuddyPress 2.5.0 * * @param string $join_sql JOIN clause. * @param array $r Method parameters. * @param string $select_sql Current SELECT MySQL statement. * @param string $from_sql Current FROM MySQL statement. * @param string $where_sql Current WHERE MySQL statement. */ $join_sql = apply_filters( 'bp_activity_get_join_sql', $join_sql, $r, $select_sql, $from_sql, $where_sql ); // Sanitize page and per_page parameters. $page = absint( $r['page'] ); $per_page = absint( $r['per_page'] ); $retval = array( 'activities' => null, 'total' => null, 'has_more_items' => null, ); /** * Filters if BuddyPress should use legacy query structure over current structure for version 2.0+. * * It is not recommended to use the legacy structure, but allowed to if needed. * * @since BuddyPress 2.0.0 * * @param bool $value Whether to use legacy structure or not. * @param BP_Activity_Activity $value Current method being called. * @param array $r Parsed arguments passed into method. */ if ( apply_filters( 'bp_use_legacy_activity_query', false, __METHOD__, $r ) ) { // Legacy queries joined against the user table. $select_sql = "SELECT DISTINCT a.*, u.user_email, u.user_nicename, u.user_login, u.display_name"; $from_sql = " FROM {$bp->activity->table_name} a LEFT JOIN {$wpdb->users} u ON a.user_id = u.ID"; if ( ! empty( $page ) && ! empty( $per_page ) ) { $pag_sql = $wpdb->prepare( "LIMIT %d, %d", absint( ( $page - 1 ) * $per_page ), $per_page ); /** This filter is documented in bp-activity/bp-activity-classes.php */ $activity_sql = apply_filters( 'bp_activity_get_user_join_filter', "{$select_sql} {$from_sql} {$join_sql} {$where_sql} ORDER BY a.date_recorded {$sort}, a.id {$sort} {$pag_sql}", $select_sql, $from_sql, $where_sql, $sort, $pag_sql ); } else { $pag_sql = ''; /** * Filters the legacy MySQL query statement so plugins can alter before results are fetched. * * @since BuddyPress 1.5.0 * * @param string $value Concatenated MySQL statement pieces to be query results with for legacy query. * @param string $select_sql Final SELECT MySQL statement portion for legacy query. * @param string $from_sql Final FROM MySQL statement portion for legacy query. * @param string $where_sql Final WHERE MySQL statement portion for legacy query. * @param string $sort Final sort direction for legacy query. */ $activity_sql = apply_filters( 'bp_activity_get_user_join_filter', "{$select_sql} {$from_sql} {$join_sql} {$where_sql} ORDER BY a.date_recorded {$sort}, a.id {$sort}", $select_sql, $from_sql, $where_sql, $sort, $pag_sql ); } /* * Queries that include 'last_activity' are cached separately, * since they are generally much less long-lived. */ if ( preg_match( '/a\.type NOT IN \([^\)]*\'last_activity\'[^\)]*\)/', $activity_sql ) ) { $cache_group = 'bp_activity'; } else { $cache_group = 'bp_activity_with_last_activity'; } $activities = $wpdb->get_results( $activity_sql ); // Integer casting for legacy activity query. foreach ( (array) $activities as $i => $ac ) { $activities[ $i ]->id = (int) $ac->id; $activities[ $i ]->item_id = (int) $ac->item_id; $activities[ $i ]->secondary_item_id = (int) $ac->secondary_item_id; $activities[ $i ]->user_id = (int) $ac->user_id; $activities[ $i ]->hide_sitewide = (int) $ac->hide_sitewide; $activities[ $i ]->mptt_left = (int) $ac->mptt_left; $activities[ $i ]->mptt_right = (int) $ac->mptt_right; $activities[ $i ]->is_spam = (int) $ac->is_spam; } } else { // Query first for activity IDs. $activity_ids_sql = "{$select_sql} {$from_sql} {$join_sql} {$where_sql} ORDER BY {$order_by} {$sort}, a.id {$sort}"; if ( ! empty( $per_page ) && ! empty( $page ) ) { // We query for $per_page + 1 items in order to // populate the has_more_items flag. $activity_ids_sql .= $wpdb->prepare( " LIMIT %d, %d", absint( ( $page - 1 ) * $per_page ), $per_page + 1 ); } /** * Filters the paged activities MySQL statement. * * @since BuddyPress 2.0.0 * * @param string $activity_ids_sql MySQL statement used to query for Activity IDs. * @param array $r Array of arguments passed into method. */ $activity_ids_sql = apply_filters( 'bp_activity_paged_activities_sql', $activity_ids_sql, $r ); /* * Queries that include 'last_activity' are cached separately, * since they are generally much less long-lived. */ if ( preg_match( '/a\.type NOT IN \([^\)]*\'last_activity\'[^\)]*\)/', $activity_ids_sql ) ) { $cache_group = 'bp_activity'; } else { $cache_group = 'bp_activity_with_last_activity'; } $cached = bp_core_get_incremented_cache( $activity_ids_sql, $cache_group ); if ( false === $cached ) { $activity_ids = $wpdb->get_col( $activity_ids_sql ); bp_core_set_incremented_cache( $activity_ids_sql, $cache_group, $activity_ids ); } else { $activity_ids = $cached; } $retval['has_more_items'] = ! empty( $per_page ) && count( $activity_ids ) > $per_page; // If we've fetched more than the $per_page value, we // can discard the extra now. if ( ! empty( $per_page ) && count( $activity_ids ) === $per_page + 1 ) { array_pop( $activity_ids ); } if ( 'ids' === $r['fields'] ) { $activities = array_map( 'intval', $activity_ids ); } else { $activities = self::get_activity_data( $activity_ids ); } } if ( 'ids' !== $r['fields'] ) { // Get the fullnames of users so we don't have to query in the loop. $activities = self::append_user_fullnames( $activities ); // Get activity meta. $activity_ids = array(); foreach ( (array) $activities as $activity ) { $activity_ids[] = $activity->id; } if ( ! empty( $activity_ids ) && $r['update_meta_cache'] ) { bp_activity_update_meta_cache( $activity_ids ); } if ( $activities && $r['display_comments'] ) { $activities = BP_Activity_Activity::append_comments( $activities, $r['spam'] ); } // Pre-fetch data associated with activity users and other objects. BP_Activity_Activity::prefetch_object_data( $activities ); // Generate action strings. $activities = BP_Activity_Activity::generate_action_strings( $activities ); } $retval['activities'] = $activities; // If $max is set, only return up to the max results. if ( ! empty( $r['count_total'] ) ) { /** * Filters the total activities MySQL statement. * * @since BuddyPress 1.5.0 * * @param string $value MySQL statement used to query for total activities. * @param string $where_sql MySQL WHERE statement portion. * @param string $sort Sort direction for query. */ $total_activities_sql = apply_filters( 'bp_activity_total_activities_sql', "SELECT count(DISTINCT a.id) FROM {$bp->activity->table_name} a {$join_sql} {$where_sql}", $where_sql, $sort ); $cached = bp_core_get_incremented_cache( $total_activities_sql, $cache_group ); if ( false === $cached ) { $total_activities = $wpdb->get_var( $total_activities_sql ); bp_core_set_incremented_cache( $total_activities_sql, $cache_group, $total_activities ); } else { $total_activities = $cached; } if ( !empty( $r['max'] ) ) { if ( (int) $total_activities > (int) $r['max'] ) { $total_activities = $r['max']; } } $retval['total'] = $total_activities; } return $retval; }

更新日志

更新日志
版本 描述
BuddyPress 1.2.0 介绍。

问题吗?

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