BP_Activity_Activity::get_id( int $user_id, string $component, string $type, int $item_id, int $secondary_item_id, string $action, string $content, string $date_recorded )
Get the first activity ID that matches a set of criteria.
Description
Parameters
- $user_id
-
(Required) User ID to filter by.
- $component
-
(Required) Component to filter by.
- $type
-
(Required) Activity type to filter by.
- $item_id
-
(Required) Associated item to filter by.
- $secondary_item_id
-
(Required) Secondary associated item to filter by.
- $action
-
(Required) Action to filter by.
- $content
-
(Required) Content to filter by.
- $date_recorded
-
(Required) Date to filter by.
Return
(int|false) Activity ID on success, false if none is found.
Source
File: bp-activity/classes/class-bp-activity-activity.php
1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 | public static function get_id( $user_id , $component , $type , $item_id , $secondary_item_id , $action , $content , $date_recorded ) { global $wpdb ; $bp = buddypress(); $where_args = false; if ( ! empty ( $user_id ) ) { $where_args [] = $wpdb ->prepare( "user_id = %d" , $user_id ); } if ( ! empty ( $component ) ) { $where_args [] = $wpdb ->prepare( "component = %s" , $component ); } if ( ! empty ( $type ) ) { $where_args [] = $wpdb ->prepare( "type = %s" , $type ); } if ( ! empty ( $item_id ) ) { $where_args [] = $wpdb ->prepare( "item_id = %d" , $item_id ); } if ( ! empty ( $secondary_item_id ) ) { $where_args [] = $wpdb ->prepare( "secondary_item_id = %d" , $secondary_item_id ); } if ( ! empty ( $action ) ) { $where_args [] = $wpdb ->prepare( "action = %s" , $action ); } if ( ! empty ( $content ) ) { $where_args [] = $wpdb ->prepare( "content = %s" , $content ); } if ( ! empty ( $date_recorded ) ) { $where_args [] = $wpdb ->prepare( "date_recorded = %s" , $date_recorded ); } if ( ! empty ( $where_args ) ) { $where_sql = 'WHERE ' . join( ' AND ' , $where_args ); $result = $wpdb ->get_var( "SELECT id FROM {$bp->activity->table_name} {$where_sql}" ); return is_numeric ( $result ) ? (int) $result : false; } return false; } |
Changelog
Version | Description |
---|---|
BuddyPress 1.2.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.