Skip to content

Instantly share code, notes, and snippets.

@codehaiku
Last active March 20, 2017 07:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codehaiku/863249c22171e1a7360a13accb2161c6 to your computer and use it in GitHub Desktop.
Save codehaiku/863249c22171e1a7360a13accb2161c6 to your computer and use it in GitHub Desktop.
<?php
function my_bp_activities_per_page_5( $retval, $bp_has_members = 'bp_has_members' ) {
global $wpdb;
$fields = array(
array(
'id' => 3,
'value' => 'male',
'relation' => 'LIKE'
),
array(
'id' => 6,
'value' => array( '0', '100' ),
'relation' => 'BETWEEN'
),
array(
'id' => 7,
'value' => 'HTML',
'relation' => 'EQUALS'
),
);
$table = $wpdb->prefix . 'bp_xprofile_data';
$included_user_ids = array();
foreach( $fields as $field ) {
if ( 'EQUALS' === $field['relation'] ) {
$query = $wpdb->prepare( "SELECT user_id FROM {$table} WHERE field_id = %d AND value = %s", $field['id'], $field['value'] );
}
if ( 'LIKE' === $field['relation'] ) {
$query = $wpdb->prepare( "SELECT user_id FROM {$table} WHERE field_id = %d AND value LIKE %s", $field['id'], '%' . $field['value'] . '%' );
}
if ( 'BETWEEN' === $field['relation'] ) {
$query = $wpdb->prepare( "SELECT user_id FROM {$table} WHERE field_id = %d AND value BETWEEN %d and %d",
$field['id'], (int)$field['value'][0], (int)$field['value'][1] );
}
$included_user_ids[] = $wpdb->get_col( $query );
$previous = array();
}
$merged_user_ids = array();
$result = call_user_func_array( 'array_intersect', $included_user_ids );
if ( empty( $result ) ) {
$retval['include'] = array(0);
} else {
$retval['include'] = $result;
}
return $retval;
}
add_filter( 'bp_after_has_members_parse_args', 'my_bp_activities_per_page_5', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment