Skip to content

Instantly share code, notes, and snippets.

@BhargavBhandari90
Created October 30, 2023 10:41
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 BhargavBhandari90/b6f9c0aa8b34fe28fb120e537e43976b to your computer and use it in GitHub Desktop.
Save BhargavBhandari90/b6f9c0aa8b34fe28fb120e537e43976b to your computer and use it in GitHub Desktop.
Set custom field to Members Search form and get result by that
<?php
function bb_bp_ps_before_search_form( $F ) {
$new = new stdClass();
$new->display = 'selectbox';
$new->code = 'age_from'; // to be removed
$new->html_name = 'age_from';
$new->value = '';
$new->unique_id = bp_ps_unique_id( 'age_from' );
$new->id = 0;
$new->label = 'Age From';
$new->options = array( 1 => 1, 2 => 2, 3 => 3, 4 => 4, );
$F->fields[] = $new;
}
add_action( 'bp_ps_before_search_form', 'bb_bp_ps_before_search_form' );
function bb_bp_ps_field_sql( $sql, $f ) {
// Do custom query for age.
return $sql;
}
add_filter( 'bp_ps_field_sql', 'bb_bp_ps_field_sql', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment