Ticket #7205: 7205-custom-orderby-2.diff
File 7205-custom-orderby-2.diff, 5.1 KB (added by , 7 years ago) |
---|
-
src/bp-activity/classes/class-bp-activity-activity.php
diff --git src/bp-activity/classes/class-bp-activity-activity.php src/bp-activity/classes/class-bp-activity-activity.php index ad1266f7c..13801e493 100644
class BP_Activity_Activity { 320 320 * 321 321 * @since 1.2.0 322 322 * @since 2.4.0 Introduced the `$fields` parameter. 323 * @since 2.9.0 Introduced the `$order_by` parameter. 323 324 * 324 325 * @see BP_Activity_Activity::get_filter_sql() for a description of the 325 326 * 'filter' parameter. … … class BP_Activity_Activity { 335 336 * @type string $fields Activity fields to return. Pass 'ids' to get only the activity IDs. 336 337 * 'all' returns full activity objects. 337 338 * @type string $sort ASC or DESC. Default: 'DESC'. 339 * @type string $order_by Column to order results by. 338 340 * @type array $exclude Array of activity IDs to exclude. Default: false. 339 341 * @type array $in Array of ids to limit query by (IN). Default: false. 340 342 * @type array $meta_query Array of meta_query conditions. See WP_Meta_Query::queries. … … class BP_Activity_Activity { 381 383 382 384 $bp = buddypress(); 383 385 $r = wp_parse_args( $args, array( 384 'page' => 1, // The current page. 385 'per_page' => 25, // Activity items per page. 386 'max' => false, // Max number of items to return. 387 'fields' => 'all', // Fields to include. 388 'sort' => 'DESC', // ASC or DESC. 389 'exclude' => false, // Array of ids to exclude. 390 'in' => false, // Array of ids to limit query by (IN). 391 'meta_query' => false, // Filter by activitymeta. 392 'date_query' => false, // Filter by date. 393 'filter_query' => false, // Advanced filtering - see BP_Activity_Query. 394 'filter' => false, // See self::get_filter_sql(). 395 'scope' => false, // Preset activity arguments. 396 'search_terms' => false, // Terms to search by. 397 'display_comments' => false, // Whether to include activity comments. 398 'show_hidden' => false, // Show items marked hide_sitewide. 399 'spam' => 'ham_only', // Spam status. 400 'update_meta_cache' => true, // Whether or not to update meta cache. 401 'count_total' => false, // Whether or not to use count_total. 386 'page' => 1, // The current page. 387 'per_page' => 25, // Activity items per page. 388 'max' => false, // Max number of items to return. 389 'fields' => 'all', // Fields to include. 390 'sort' => 'DESC', // ASC or DESC. 391 'order_by' => 'date_recorded', // Column to order by. 392 'exclude' => false, // Array of ids to exclude. 393 'in' => false, // Array of ids to limit query by (IN). 394 'meta_query' => false, // Filter by activitymeta. 395 'date_query' => false, // Filter by date. 396 'filter_query' => false, // Advanced filtering - see BP_Activity_Query. 397 'filter' => false, // See self::get_filter_sql(). 398 'scope' => false, // Preset activity arguments. 399 'search_terms' => false, // Terms to search by. 400 'display_comments' => false, // Whether to include activity comments. 401 'show_hidden' => false, // Show items marked hide_sitewide. 402 'spam' => 'ham_only', // Spam status. 403 'update_meta_cache' => true, // Whether or not to update meta cache. 404 'count_total' => false, // Whether or not to use count_total. 402 405 ) ); 403 406 404 407 // Select conditions. … … class BP_Activity_Activity { 461 464 $sort = 'DESC'; 462 465 } 463 466 467 switch( $r['order_by'] ) { 468 case 'id' : 469 case 'user_id' : 470 case 'component' : 471 case 'type' : 472 case 'action' : 473 case 'content' : 474 case 'primary_link' : 475 case 'item_id' : 476 case 'secondary_item_id' : 477 case 'date_recorded' : 478 case 'hide_sitewide' : 479 case 'mptt_left' : 480 case 'mptt_right' : 481 case 'is_spam' : 482 break; 483 484 default : 485 $r['order_by'] = 'date_recorded'; 486 break; 487 } 488 $order_by = 'a.' . $r['order_by']; 489 464 490 // Hide Hidden Items? 465 491 if ( ! $r['show_hidden'] ) { 466 492 $where_conditions['hidden_sql'] = "a.hide_sitewide = 0"; … … class BP_Activity_Activity { 607 633 608 634 } else { 609 635 // Query first for activity IDs. 610 $activity_ids_sql = "{$select_sql} {$from_sql} {$join_sql} {$where_sql} ORDER BY a.date_recorded{$sort}, a.id {$sort}";636 $activity_ids_sql = "{$select_sql} {$from_sql} {$join_sql} {$where_sql} ORDER BY {$order_by} {$sort}, a.id {$sort}"; 611 637 612 638 if ( ! empty( $per_page ) && ! empty( $page ) ) { 613 639 // We query for $per_page + 1 items in order to