• Hi!!! I need some help please!!

    I would like to use two different search forms in my site, the client needs one for general search and one ONLY for attachments…
    I already made this (attachments), but I’m having problems with the other one…
    I think maybe could create a function for each but I don’t know how to call it in each get_search_form …

    Please help!! thank’s!!!

Viewing 1 replies (of 1 total)
  • Hi @iraislua,

    You can hook to get_search_form filter that accept the form as string parameter and with some string search build and return your own.

    Or, you can create a new wrapper function for get_search_form that take a parameter $which, so you can call the function to retrieve the custom form.

    For example
    my_search_form(‘custom-form’);
    my_search_form(‘posts-form’);

    etc…

    function my_search_form($which = '', $echo = true ) {
    	// If the parameter is an empty string, call the default function.
    	// Otherwise build your own. You can add multiple case statements to create a lot's of custom forms.
    	switch ( $which ) {
    		case 'custom-search' :
    			$form = '<form>YOUR FORM CONTENT</form>';
    			break;
    		default :
    			$form = get_search_form(false);
    			break;
    	}
    
    	if ( ! $echo ) {
    		return $form;
    	}
    
    	echo $form;
    }
Viewing 1 replies (of 1 total)

The topic ‘Different get_search_form for different functions’ is closed to new replies.