<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>function &#8211; Blackbams Blog</title>
	<atom:link href="https://blog.blackbam.at/tag/function/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.blackbam.at</link>
	<description>development - digital arts - internet</description>
	<lastBuildDate>Sun, 24 Jun 2012 23:19:00 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.1</generator>
	<item>
		<title>WordPress improved user search (first name, last name, email) in backend</title>
		<link>https://blog.blackbam.at/2011/06/27/wordpress-improved-user-search-first-name-last-name-email-in-backend/</link>
					<comments>https://blog.blackbam.at/2011/06/27/wordpress-improved-user-search-first-name-last-name-email-in-backend/#comments</comments>
		
		<dc:creator><![CDATA[Blackbam]]></dc:creator>
		<pubDate>Mon, 27 Jun 2011 22:35:01 +0000</pubDate>
				<category><![CDATA[Plugins]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WP Scripts]]></category>
		<category><![CDATA[backend]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[search]]></category>
		<guid isPermaLink="false">https://blog.blackbam.at/?p=1457</guid>

					<description><![CDATA[Recently, when working on a WordPress website for a huge amount of users, a customer was unsatisfyied with the WordPress backend search for users. The default backend search only is searching for your search string in usernames, but not for first name, last name or email of users. &#160; As most WordPress projects are barely [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Recently, when working on a WordPress website for a huge amount of users, a customer was unsatisfyied with the WordPress backend search for users. The default backend search only is searching for your search string in usernames, but not for first name, last name or email of users.</p>
<p>&nbsp;</p>
<p>As most WordPress projects are barely designed to have a huge amoung of users, this is not necessary in most cases. Anyway, the following code will help with this problem &#8211; add this to your functions.php-file and the WordPress user search will scan first name, last name and e-mail of every user.</p>
<p>&nbsp;</p>
<p style="text-align:center;"><a href="http://wordpress.org/extend/plugins/improved-user-search-in-backend/">Download the official WordPress Plugin</a></p>
<div class="code_title">How the Plugin basically works (code overview of Version 1.2)</div>
<pre lang="php">
 
   // the actual improvement of the query
    function user_search_by_multiple_parameters($wp_user_query) {
        if(false === strpos($wp_user_query -> query_where, '@') && !empty($_GET["s"])) {

            global $wpdb;

            $uids=array();

			// get the custom meta fields to search
			$iusib_custom_meta = get_option('iusib_meta_fields');
			$iusib_cma = array_map('trim', explode(",",$iusib_custom_meta));

			$iusib_add = "";
			// the escaped query string
			$qstr = mysql_real_escape_string($_GET["s"]);
			
			// add all custom fields into the query
			if(!empty($iusib_cma)) {
				$iusib_add = " OR meta_key='".implode("' OR meta_key='",$iusib_cma)."'";
			}

            $usermeta_affected_ids = $wpdb -> get_results("SELECT DISTINCT user_id FROM ".$wpdb->base_prefix."usermeta WHERE (meta_key='first_name' OR meta_key='last_name'".$iusib_add.") AND LOWER(meta_value) LIKE '%".$qstr."%'");

            foreach($usermeta_affected_ids as $maf) {
                array_push($uids,$maf->user_id);
            }

            $users_affected_ids = $wpdb -> get_results("SELECT DISTINCT ID FROM ".$wpdb->base_prefix."users WHERE LOWER(user_nicename) LIKE '%".$qstr."%' OR LOWER(user_email) LIKE '%".$qstr."%'");

            foreach($users_affected_ids as $maf) {
                if(!in_array($maf->ID,$uids)) {
                    array_push($uids,$maf->ID);
                }
            }
			
            $id_string = implode(",",$uids);

            $wp_user_query -> query_where = str_replace("user_nicename LIKE '%".$qstr."%'", "ID IN(".$id_string.")", $wp_user_query -> query_where);
        }
        return $wp_user_query;
    }

</pre>
<p><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fblog.blackbam.at%2F2011%2F06%2F27%2Fwordpress-improved-user-search-first-name-last-name-email-in-backend%2F&#038;title=WordPress%20improved%20user%20search%20%28first%20name%2C%20last%20name%2C%20email%29%20in%20backend" data-a2a-url="https://blog.blackbam.at/2011/06/27/wordpress-improved-user-search-first-name-last-name-email-in-backend/" data-a2a-title="WordPress improved user search (first name, last name, email) in backend"><img src="https://static.addtoany.com/buttons/share_save_120_16.png" alt="Share"></a></p>]]></content:encoded>
					
					<wfw:commentRss>https://blog.blackbam.at/2011/06/27/wordpress-improved-user-search-first-name-last-name-email-in-backend/feed/</wfw:commentRss>
			<slash:comments>74</slash:comments>
		
		
			</item>
	</channel>
</rss>
