• Is there a way to pass multiple input value to search result page? My code below and I really struggling how to do this. It only work if first name is search however I am having problem if other input fields is added to the search.

    My Input search:

    first_name
    age
    section

    <form method="get" id="searchform" action="<?php echo home_url( '/' ); ?>">
    		    <fieldset id="custom_search">
    		    <legend>Custom Search</legend>
    		        <label for="s">Search for First Name (required)</label><br/>
    		        <input type="text" name="s" id="s" value="search for name.." onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;"/><br/>
    		        <input type="image" alt="Search" src="<?php bloginfo( 'template_url' ); ?>/images/search.png" /><br/>
    
    		        <label for="age">Search according to Age (optional)</label><br/>
    		        <input type="text" name="age" id="age" value="search for age.." onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;" />
    		        <input type="image" alt="Search" src="<?php bloginfo( 'template_url' ); ?>/images/search.png" /><br/>
    
    		        <label for="gender">Search according Gender (optional)</label><br/>
    				<input type="text" name="gender" id="gender" value="search gender.." onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;" />
    		        <input type="image" alt="Search" src="<?php bloginfo( 'template_url' ); ?>/images/search.png" /><br/>
    
    		        <label for="section">Search for Section (optional)</label><br/>
    				<input type="text" name="section" id="rate" value="section...." onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;" />
    		        <input type="image" alt="Search" src="<?php bloginfo( 'template_url' ); ?>/images/search.png" /><br/>
    
    		    </fieldset>
    		</form>

    My search.php query code

    <?php
    
    	global $wpdb;
    	$fname= preg_replace( '/[^0-9]/', '', $_GET['s'] ); //only allow numbers
    	$age = preg_replace( '/[^0-9]/', '', $_GET['age'] );
            $section = preg_replace( '/[^0-9]/', '', $_GET['section'] );
    
    	if ($fname!= '')
    	{
    	//Process Inputs
    			$query = "SELECT user_id FROM $wpdb->usermeta
    				WHERE ( meta_value LIKE '%%$fname%%' )
    				AND ( meta_key = 'first_name' )
    				AND user_id IN ( SELECT user_id FROM $wpdb->usermeta WHERE (meta_value= 'student') AND (meta_key = 'entity'))";
    
    			$query_fname = $wpdb->get_results($query);
    
    			//Display Header Title
    			echo '<h2>' . 'Students List' . '</h2>';
    
    			foreach ($query_fname as $query_fname1 ) {
    
    			//Query User Information
    				$userinfo=get_userdata( $query_fname1->user_id );
    
    			//Display Results
    			echo '<li>' . $userinfo->first_name . ' ' . $userinfo->last_name . '</li>';
    					}

    Currently it display only according to first name search.

    What I need to query the results if the user filled up other fields.

  • The topic ‘multiple input search from usermeta tables’ is closed to new replies.