WordPress.org

Ready to get started?Download WordPress

Forums

Search Everything
Fix for author search (4 posts)

  1. Armin Ro?u
    Member
    Posted 3 years ago #

    Here's the filters I applied to enable username searching (also does firstname and lastname search). Hope it helps you (wouldn't mind a mention if it does ;) ):

    function search_author_join( $join )
    {
    	if( is_search()  ) {
    		global $wpdb;
    
    		$join .= "
    			LEFT JOIN (SELECT ID AS uid, display_name FROM $wpdb->users) AS u ON $wpdb->posts.post_author = u.uid
    			LEFT JOIN (SELECT user_id AS umid1, meta_value AS first_name FROM $wpdb->usermeta WHERE meta_key='first_name') AS um1 ON $wpdb->posts.post_author = um1.umid1
    			LEFT JOIN (SELECT user_id AS umid2, meta_value AS last_name FROM $wpdb->usermeta WHERE meta_key='last_name') AS um2 ON $wpdb->posts.post_author = um2.umid2
    		";
    	}
    
    	return $join;
    }
    add_filter('posts_join', 'search_author_join');
    
    function search_author_where( $where )
    {
    	if( is_search() )
    	{
    		global $wp_query, $wpdb;
    		$search_string = $wp_query->query_vars['s'];
    
    		$where .= " OR (
    				(
    					display_name LIKE '%$search_string%'
    					OR first_name LIKE '%$search_string%'
    					OR last_name LIKE '%$search_string%'
    				)
    				AND $wpdb->posts.post_type='post'
    				AND $wpdb->posts.post_status='publish'
    			)
    		";
    	}
    	return $where;
    }
    add_filter('posts_where', 'search_author_where');

    http://wordpress.org/extend/plugins/search-everything/

  2. DarioDN
    Member
    Posted 2 years ago #

    Where have we to paste this code?

  3. Armin Ro?u
    Member
    Posted 2 years ago #

    in your functions.php file

  4. arthurdent2003
    Member
    Posted 2 years ago #

    doesn't work for me...thanks so far...

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic