Skip to:
Content
Pages
Categories
Search
Top
Bottom

Impossible to get avatars in a custom AJAX search?

  • @jamz86

    Member

    Hi,

    I’m running BP 1.2.8 on WP 3.1 and I’ve created an AJAX/jQuery live search that’s a lot like Facebook’s. It works fine — however, no matter what I try, it seems to break every time I try to add avatars to the search results.

    Here’s the code I’m trying:

    
    $query_m = "SELECT ID, user_url, display_name FROM {$wpdb->prefix}_users WHERE display_name LIKE '%$keyword%' ORDER BY ID LIMIT 8";
    $result_m = mysqli_query($dbc,$query_m);
    if($result_m){
    if(mysqli_affected_rows($dbc)!=0){
    
    echo '<span class="category">Members</span>';
    
    while($row = mysqli_fetch_array($result_m,MYSQLI_ASSOC)){
    
    if(strlen($row) > 35) {
    $row = substr($row, 0, 35) . "...";
    }
    
    echo '<span class="searchheading"><a href="'.$row.'">'.$row.'</a></span>';
    
    echo bp_core_fetch_avatar('item_id='.$row );
    }
    }else {
    echo 'No Results for :"'.$_GET.'" in Members';
    }
    
    }
    

    I’ve also tried calling the $bp global right before bp_core_fetch_avatar, but it doesn’t seem to make a difference.

    Any help would be greatly appreciated!

Viewing 5 replies - 1 through 5 (of 5 total)
  • @boonebgorges

    Keymaster

    Exactly what is your AJAX returning? Is the first part (span.searchheading) coming through OK?

    You might try (just for the heck of it) switching your argument structure to an array, something like this:
    echo bp_core_fetch_avatar( array( 'item_id' => $row ) );

    Theoretically, it shouldn’t matter, but sometimes it does.

    If you’re still having troubles, start dropping var_dump() statements into bp_core_fetch_avatar() itself. You can find that function in bp-core/bp-core-avatars.php.

    @jamz86

    Member

    Hi @Stacy, thanks! Is the code written correctly? When I copied it into bp-custom in Dreamweaver it said the code was invalid. Thanks so much, though.

    @jamz86

    Member

    Hi @boonebgorges, I’ve tried the array structure, and the problem is still there. I’ve never done var_dump() before, so I’m a little confused. Could you show me the code I should put in?

    @jamz86

    Member

    bump!

    @jamz86

    Member

    bump? is this really that hard?

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Impossible to get avatars in a custom AJAX search?’ is closed to new replies.
Skip to toolbar