• Resolved Janet L.

    (@janet-l)


    When I add the BP Profile Search extended profile fields to the directory orderby I can order all directory items by one of those fields. However, if I do a search I can not have the search results ordered by an extended profile field. If I leave it on the extended profile field I get all entries. When I switch back to alphabetic or last active then search I get the filtered results. Thanks for any help you can give with this problem.

    https://wordpress.org/plugins/bp-profile-search/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Andrea Tarantini

    (@dontdream)

    Hi Janet,

    Could you please detail how you are ordering the members directory by an extended profile field? Are you using a plugin or some custom code?

    Thread Starter Janet L.

    (@janet-l)

    Andrea,

    I am using some custom code in the functions.php file. I have extended bp_members_directory_order_options to add my Profile Search fields. And I have extended bp_pre_user_query to add the sql code to sort based on those fields. I think that is where it is going wrong, that I have the full members directory and not what the Profile Search created but I am not seeing where else to hook that in.

    Thanks for your help.

    Plugin Author Andrea Tarantini

    (@dontdream)

    Janet,

    If you wish you can send me your code, and if I’m lucky I might find the way to make it work with BP Profile Search. My email is andrea@dontdream.it

    Thread Starter Janet L.

    (@janet-l)

    Andrea – Thank you so much for your help!! For anyone that might alo be having this problem I will include my function below with the update that Andrea provided.

    // sort ajax members by HSF profile information
    function users_sortby_hsf( $object ) {
    global $wpdb, $bp;

    // Only run this if hsf option is selected
    if ( ! in_array( $object->query_vars[‘type’], array( ‘AwardYear’, ‘Residence’, ‘Institution’, ‘Major’ ) ) )
    return;

    $field_id = $wpdb->get_var( $wpdb->prepare( “SELECT id FROM {$bp->profile->table_name_fields} WHERE name = %s”, $object->query_vars[‘type’] ) );

    $object->uid_name = ‘user_id’;
    $object->uid_table = $bp->profile->table_name_data;
    $object->uid_clauses[‘select’] = “SELECT u.{$object->uid_name} as id FROM {$object->uid_table} u”;
    $object->uid_clauses[‘where’] = ” WHERE ” . $wpdb->prepare( “u.field_id = %d”, $field_id );

    // code for BP Profile Search
    $include = $object->query_vars[‘include’];
    if (!empty ($include))
    $object->uid_clauses[‘where’] .= ” AND u.{$object->uid_name} IN ($include)”;
    // end code for BP Profile Search

    $object->uid_clauses[‘orderby’] = “ORDER BY u.value”;
    $object->uid_clauses[‘order’] = “ASC”;

    }
    add_action( ‘bp_pre_user_query’, ‘users_sortby_hsf’ );

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘BP Profile Search not working with extended profile field orderby.’ is closed to new replies.