Better Search
[resolved] search by user profile and post title (6 posts)

  1. a77a77
    Posted 2 years ago #

    This plugin is amaizing!
    I need search only for user registred to show users profiles,
    and search too for post title only,
    I can do it with this plugin?

    Thanks for Any help!


  2. Ajay
    Plugin Author

    Posted 2 years ago #

    You can only search for posts. The plugin doesn't allow you to find users / user profiles.

  3. adrianlittee
    Posted 2 years ago #

    I have integrated this functionality into the Plugin myself. It was surprisingly easy if you have a moderate knowledge of PHP and MySQL.

  4. Ajay
    Plugin Author

    Posted 2 years ago #

    @adrianlittee, would you like to share the code with other users?

  5. adrianlittee
    Posted 2 years ago #

    Here is what I used and forgive me if it is rough and not using WP standards but I threw it together pretty quickly for work.

    My Query is using user meta which we are importing from an active directory server so it may not me in your system. Hopefully it will be at least a start for anyone wondering how to get it working.

    //Employee Results
    echo '<div id="employee-results">';
    echo '<h1 class="page-title">';
    echo __( 'Employee Results', BSEARCH_LOCAL_NAME );
    echo '</h1>';
    $min = 0;
    $max = 1;
    //query info
    $user_tab = 'wp_usermeta';
    $user_query = "SELECT * FROM $user_tab WHERE meta_value LIKE '%$s%' AND (meta_key = 'adi_displayname' OR meta_key = 'title')";
    $user_sql = mysql_query($user_query);
    $count_emp = mysql_num_rows($user_sql);
    //displaying the query and employee results
    if($count_emp > $min){
    	while($user = mysql_fetch_array($user_sql)){
    		$user_id = $user['user_id'];
    		$meta_table = 'wp_usermeta';
    		$meta = get_user_meta($user_id);
    		$author = $meta['first_name'][$min].'-'.$meta['last_name'][$min];
    		echo '<div class="employee_results post-entry">';
    		echo '<h2><strong><a href="http://mydomain.com/author/'.$author.'">'.$meta['adi_displayname'][$min].'</strong></a> - '.$meta['title'][$min].'</h2>';
    		echo '<a href="http://mydomain.com/author/'.$author.'">'.get_avatar($user_id, 32).'</a>';
    		echo '</div>';
    } else {
    	echo 'There are no employee results for: '.$s;
    echo '</div>';

    I inserted the code into the better-search.php page. I spit the page in two so it would display employee results on one side and better-search results on the other side. Hope this helped :)

  6. Ajay
    Plugin Author

    Posted 2 years ago #

    Thanks for sharing the code. It does make sense for users targeting employee search or similar user results.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Better Search
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic