Filtering Members Loop with Custom Data and URL Querystring
-
Hi,
I’m running BuddyBoss/BuddyPress on WordPress 5.3.2
I’d like to be able to filter my main BuddyPress members page using $_GET, from query variables passed in the URL.
I’ve tried various ideas found on the web and the most up to date/promising way of doing this seems to be using bp_parse_args() via…
add_filter( 'bp_after_has_members_parse_args', 'my_function' );
Using this method works well except for the fact that I am unable to access my passed filter variables via $_GET …if I print the site url from within my function it returns wp-admin/ajax.php (or something like it) which I guess is why I can’t access the passed query variables. Any help with this would be greatly appreciated.
Many thanks,
Antony
My code…
function ic_members_filter( $retval ) { global $wpdb; global $ic_filter_members_interest_id; if( $ic_filter_members_interest_id && $ic_filter_members_interest_id>0 ){ $prepared_statement = $wpdb->prepare( "SELECT user_id FROM ic_interests_data WHERE interest_id = %d AND (interest_value = 1 OR interest_value = 3)", $ic_filter_members_interest_id ); $db_custom_ids = $wpdb->get_col( $prepared_statement ); if ( $db_custom_ids ) { //!empty( $db_custom_ids ) // convert the array to a csv string $retval['include'] = implode(",", $db_custom_ids); //$custom_ids_str = 'include=' . implode(",", $custom_ids); } else{ // don't show any records $retval['include'] = array(0); } }else{ // show all records $retval['include'] = ''; } return $retval; } add_filter( 'bp_after_has_members_parse_args', 'ic_members_filter' );
WHERE… $ic_filter_members_interest_id is a global that holds the interest_id via $_GET
References…
https://buddypress.trac.wordpress.org/browser/tags/2.2.1/src/bp-members/bp-members-template.php#L461
- You must be logged in to reply to this topic.