I have a profile field with checkboxes where users can check their "interests". I'd like to customize the activity feed by scoping it down with a search string including the users interests. Following the search term method here (the example with "nap"): http://premium.wpmudev.org/blog/how-to-customize-the-buddypress-activity-loop/
I have this at the top of activity-loop.php:
<?php
$activity_search_terms = "&search_terms=";
if ( $interests = xprofile_get_field_data( 'Interests', bp_loggedin_user_id() ) ) {
foreach ( $interests as $interest ) {
$activity_search_terms .= strtolower($interest) . "+";
}
}
?>
<?php if ( bp_has_activities( bp_ajax_querystring( 'activity' ) . rtrim($activity_search_terms, '+') ) ) : ?>
This would work perfectly if the activity search were using an OR query instead of an AND query. Right now if a user clicks "yoga" and "crossfit" as interests, the activity feed is only posts with BOTH those terms instead of EITHER.
I installed Relevanssi and have it set to OR query, but it doesn't appear to apply to the activity search. Is there a way to force an OR query for bp_has_activities
?
Using WP 4.1 and BP 2.1.1
UPDATE:
I have it working via modifying BuddyPress bp-activity\bp-activity-classes.php
around L.346 to write a LIKE statement for each search term. If you can tell me how to achieve the same thing in a plugin (without having to avoid $wpdb->prepare
), the bounty is yours!
// Searching
if ( $search_terms ) {
$search_terms_array = explode(' ', $search_terms);
// WAS: $search_terms_like = '%' . bp_esc_like( $search_terms ) . '%';
$search_terms_like = '';
foreach( $search_terms_array as $term)
$search_terms_like .= 'a.content LIKE \'%' . bp_esc_like( $term ) . '%\' OR ';
$where_conditions['search_sql'] = rtrim($search_terms_like, ' OR ');
// WAS: $where_conditions['search_sql'] = $wpdb->prepare( 'a.content LIKE %s', $search_terms_like);
}