Changeset 6950 for trunk/bp-groups/bp-groups-classes.php
- Timestamp:
- 04/26/2013 06:50:47 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-groups/bp-groups-classes.php
r6712 r6950 335 335 'user_id' => 0, 336 336 'search_terms' => false, 337 'meta_query' => false, 337 338 'include' => false, 338 339 'populate_extras' => true, … … 366 367 $search_terms = like_escape( $wpdb->escape( $search_terms ) ); 367 368 $sql['search'] = " AND ( g.name LIKE '%%{$search_terms}%%' OR g.description LIKE '%%{$search_terms}%%' )"; 369 } 370 371 $meta_query_sql = self::get_meta_query_sql( $meta_query ); 372 373 if ( ! empty( $meta_query_sql['join'] ) ) { 374 $sql['from'] .= $meta_query_sql['join']; 375 $total_sql['select'] .= $meta_query_sql['join_total']; 376 } 377 378 if ( ! empty( $meta_query_sql['where'] ) ) { 379 $sql['meta'] = $meta_query_sql['where']; 368 380 } 369 381 … … 465 477 return array( 'groups' => $paged_groups, 'total' => $total_groups ); 466 478 } 479 480 /** 481 * Get the SQL for the 'meta_query' param in BP_Activity_Activity::get() 482 * 483 * We use WP_Meta_Query to do the heavy lifting of parsing the 484 * meta_query array and creating the necessary SQL clauses. However, 485 * since BP_Activity_Activity::get() builds its SQL differently than 486 * WP_Query, we have to alter the return value (stripping the leading 487 * AND keyword from the 'where' clause). 488 * 489 * @since 1.8 490 * 491 * @param array $meta_query An array of meta_query filters. See the 492 * documentation for WP_Meta_Query for details. 493 * @return array $sql_array 'join' and 'where' clauses 494 */ 495 public static function get_meta_query_sql( $meta_query = array() ) { 496 global $wpdb; 497 498 $sql_array = array( 499 'join' => '', 500 'where' => '', 501 ); 502 503 if ( ! empty( $meta_query ) ) { 504 $groups_meta_query = new WP_Meta_Query( $meta_query ); 505 506 // WP_Meta_Query expects the table name at 507 // $wpdb->group 508 $wpdb->groupmeta = buddypress()->groups->table_name_groupmeta; 509 510 $meta_sql = $groups_meta_query->get_sql( 'group', 'g', 'id' ); 511 512 // BP_Groups_Group::get uses the comma syntax for table 513 // joins, which means that we have to do some regex to 514 // convert the INNER JOIN and move the ON clause to a 515 // WHERE condition 516 // 517 // @todo It may be better in the long run to refactor 518 // the more general query syntax to accord better with 519 // BP/WP convention 520 preg_match( '/INNER JOIN (.*) ON/', $meta_sql['join'], $matches_a ); 521 preg_match( '/ON \((.*)\)$/', $meta_sql['join'], $matches_b ); 522 if ( ! empty( $matches_a[1] ) && ! empty( $matches_b[1] ) ) { 523 $sql_array['join'] = $matches_a[1] . ', '; 524 $sql_array['where'] = preg_replace( '/^(\sAND\s+[\(\s]+)/', '$1' . $matches_b[1] . ' AND ', $meta_sql['where'] ); 525 } 526 } 527 528 return $sql_array; 529 } 530 467 531 468 532 function get_by_most_forum_topics( $limit = null, $page = null, $user_id = 0, $search_terms = false, $populate_extras = true, $exclude = false ) {
Note: See TracChangeset
for help on using the changeset viewer.