Hello Brajesh
Another big thank you for the help given.
For the masking of the field, it is only possible to restrict the display of the field to “me” (to my knowledge with buddypress). There is a plugin (obsolete) https://fr.wordpress.org/plugins/buddypress-admin-only-profile-fields/ so that the administrator is the only person who sees it but I still have the masking by css
For the filling, I’m looking but not sure that I can do it with a single request!
As I did not understand in the code, the warning that there could be a problem “do not filter on the friends page. It will be problemetic as it won’t filter the widget/shortcode on the friends page”. I wonder if this could improve the code
add_action( ‘bp_pre_user_query_construct’, ‘buddydev_filter_members_list_herve’, 0 );
function buddydev_filter_members_list_herve( $query ) {
if ( bp_is_members_directory() ) { ////////////////////// bp_is_members_directory()
if ( ! is_user_logged_in() ) {
return;
}$user_id = get_current_user_id();
$field_jesuis = ’57’;
$field_jerecherche = ’60’;
$recherche_de = xprofile_get_field_data( $field_jerecherche, $user_id );/* EX buddy a $user_id = get_current_user_id();
// get the value for the field.
// Use field id for better performance.
$searching_for = xprofile_get_field_data( ‘I search’, $user_id, ‘comma’ ); */if ( empty( $recherche_de ) ) {
return;
}/////////////////////////////******************if ( bp_is_user_friends() ) {
return;// do not filter on the friends page. It will be problemetic as it won’t filter the widget/shortcode on the friends page.
} *********************////////////////////////$xprofile_query = isset( $query->query_vars[‘xprofile_query’] ) ? $query->query_vars[‘xprofile_query’] : array();
$xprofile_query[] = array(
‘field’ => $field_jesuis,
‘value’ => $recherche_de,
‘compare’ => ‘=’,
);//photo_priorite
$xprofile_query[] = array(
‘field’ => ‘photo_priorite’,
‘value’ => 3,
‘compare’ => ‘>=’,
‘type’ => ‘NUMERIC’,
);if ( ! empty( $xprofile_query ) ) {
$query->query_vars[‘xprofile_query’] = $xprofile_query;
}
return $query;} ////////////////////// bp_is_members_directory() END
}Regards
Hi Herve,
Thank you.Can you please post me your xprofile field id. I may be able to put some css.
For posting code here, please wrap it inside backtick(`) . I am not sure form above code .
If you only want to filter on directory, It can have similar condition.
Regards
BrajeshHello Brajesh
form#profile-edit-form div.editfield.field_503 {display:none!important} /* masque le champ 503 (onglet apparence) */ tr.field_503 {display:none!important}
I think I css them are good!?
I submit the change. It must be understood that your code works well. This is your warning that I would not want to have a problem later
Regards
add_action( ‘bp_pre_user_query_construct’, ‘buddydev_filter_members_list_herve’, 0 ); function buddydev_filter_members_list_herve( $query ) { if ( bp_is_members_directory() ) { ////////////////////// bp_is_members_directory() if ( ! is_user_logged_in() ) { return; } ... /* EX buddy a $user_id = get_current_user_id(); // get the value for the field. // Use field id for better performance. $searching_for = xprofile_get_field_data( ‘I search’, $user_id, ‘comma’ ); */ if ( empty( $recherche_de ) ) { return; } /////////////////////////////******************if ( bp_is_user_friends() ) { return;// do not filter on the friends page. It will be problemetic as it won’t filter the widget/shortcode on the friends page. } *********************//////////////////////// $xprofile_query = isset( $query->query_vars[‘xprofile_query’] ) ? $query->query_vars[‘xprofile_query’] : array(); $xprofile_query[] = array( ‘field’ => $field_jesuis, ‘value’ => $recherche_de, ‘compare’ => ‘=’, ); //photo_priorite $xprofile_query[] = array( ‘field’ => ‘photo_priorite’, ‘value’ => 3, ‘compare’ => ‘>=’, ‘type’ => ‘NUMERIC’, ); if ( ! empty( $xprofile_query ) ) { $query->query_vars[‘xprofile_query’] = $xprofile_query; } return $query; } ////////////////////// bp_is_members_directory() END }
Hi Herve,
Thank you.
I misunderstood it earlier. No, That was not a warning.
It was simply a note that on the friends screen, we are not filtering , so if you are using it to hide users from widget etc, they will be visible.
I was concerned that you may be using it to create some sort of privacy.
I think, I will choose better words for note in future 🙂Regards
BrajeshHello Brajesh
I changed the type of numeric field to a select (to enter only certain values
I put in the program
$ xprofile_query [] = array (
‘field’ => ‘photo_note’,
‘value’ => 4,
‘compare’ => ‘> =’,
‘type’ => ‘SELECT’,
It does not work. I imagine that it is the type of field or the comparator which is not correctThanks for your help*
Regards
Hervé* and for the other 🙂
https://buddydev.com/support/forums/topic/to-the-connection-of-an-existing-member-change-role-plan/#post-15065Hi Herve,
Please login to dashboard. Visit Users->profile Fields and click on Edit for the above profile field.Please link me to a screenshot of the options you have created. I can assist better.
Also, the above query is incorrect. Please link me and I will assist with it.
For the other, I will be spending sometime on that today/tomorrow.
Regards
BrajeshHello Brajesh
https://screenshots.firefox.com/ThmtLfhSwYgeZo0A/null
thank you for your patience
Have a good dayadd_action( 'bp_pre_user_query_construct', 'buddydev_filter_members_list_herve', 0 ); function buddydev_filter_members_list_herve( $query ) { if ( ! is_user_logged_in() ) { return; } $user_id = get_current_user_id(); $field_jesuis = '57'; $field_jerecherche = '60'; $recherche_de = xprofile_get_field_data( $field_jerecherche, $user_id ); if ( empty( $recherche_de ) ) { return; } if ( bp_is_user_friends() ) { return;// non appliqué si page amis (ne filtre pas sur la page des amis. Ce sera problématique car il ne filtrera pas le widget / shortcode sur la page des amis). } $xprofile_query = isset( $query->query_vars['xprofile_query'] ) ? $query->query_vars['xprofile_query'] : array(); $xprofile_query[] = array( 'field' => $field_jesuis, 'value' => $recherche_de, 'compare' => '=', ); /* if ( bp_is_members_directory() ) { // DOES NOT WORK $xprofile_query[] = array( 'field' => 'photo_note', 'value' => 4, 'compare' => '>=', 'type' => 'SELECT', ); } if ( bp_is_members_directory() ) { // WORKS $xprofile_query[] = array( 'field' => 'photo_note', 'value' => 4, 'compare' => '>=', 'type' => 'NUMERIC', ); } */ if ( ! empty( $xprofile_query ) ) { $query->query_vars['xprofile_query'] = $xprofile_query; } return $query; }
Hi Herve,
You should use this one$xprofile_query[] = array( 1field' => 'photo_note', 'value' => 4, 'compare' => '>=', 'type' => 'NUMERIC', );
The type is Numeric as the values are of numeric type. It has nothing to do with the field type.
Regards
BrajeshHello Brajesh
Have there been any changes with buddypress 3.0!
I just put
1 / the field with a numeric field instead of a select field
2 / the program below
like what worked a few months agoResults:
I have the first filter that works.
2nd filter on photo_note no longer works
Regardsfunction buddydev_filter_members_list_herve( $query ) { if ( ! is_user_logged_in() ) { return; } $user_id = get_current_user_id(); // get the value for the field. // Use field id for better performance. $searching_for = xprofile_get_field_data( 'Je recherche', $user_id, 'comma' ); if ( empty( $searching_for ) ) { return; } if ( bp_is_user_friends() ) { return;// do not filter on the friends page. It will be problemetic as it won't filter the widget/shortcode on the friends page. } $xprofile_query = isset( $query->query_vars['xprofile_query'] ) ? $query->query_vars['xprofile_query'] : array(); $xprofile_query[] = array( 'field' => 'Je suis', // I suggest using field id for more efficiency. 'value' => $searching_for, 'compare' => '=', ); if ( bp_is_members_directory() ) { //photo_priorite $xprofile_query[] = array( 'field' => 'photo_note', 'value' => 5, 'compare' => '>=', 'type' => 'NUMERIC', ); } if ( ! empty( $xprofile_query ) ) { $query->query_vars['xprofile_query'] = $xprofile_query; } return $query; } add_action( 'bp_pre_user_query_construct', 'buddydev_filter_members_list_herve', 0 );
Hi Herve,
I am not aware of any changes.Are you sure it is not working. The above code will only list members whose photo_note has value 5 or above(6,7,8..) and the field “Je suis” matched the search.
Please give it another try.
Regards
Brajesh
The topic ‘filter the buddypress members in the list of members’ is closed to new replies.