This topic has 1 reply, 2 voices, and was last updated 6 years by Kieran_SQ.

  • Author
  • #188507
     Cairy
    Participant

    Hi,

    is it possible to add a custom search form with a shortcode? It should search just one category.

    Regards

    #188567
     Kieran_SQ
    Moderator

    Hi,

    You can use the below HTML snippet within your page(s) etc to show a form that only searches a specific category

    COPY CODE
    <div id="search-5" class="widget widget_search"><form role="search" method="get" id="searchform" action="http://localhost/kleo/">
    	
    	<div class="input-group">
    		<input name="s" id="s" autocomplete="off" type="text" class="ajax_s form-control input-sm" value="" placeholder="Search this category only" style="opacity: 1;">
    <input type="hidden" value="32" name="cat" id="specificcat" />
    		<span class="input-group-btn">
                <input type="submit" value="Search" id="searchsubmit" class="button">
    		</span>
    	</div>
    
    </form></div>

    Change the value=”32″ in the above example to be the ID of your category and change placeholder=”Search this category only” to your desired term, if any. Make sure to update the action=”” URL to match your own domain.

    If you would like to turn this into a shortcode as you describe above please use this PHP snippet instead in your KLEO Child theme’s functions.php file

    COPY CODE
    // Custom Shortcode for specific search 
    // Add Shortcode
    function custom_shortcode_sq_cat_search() { echo ('<div id="search-5" class="widget widget_search"><form role="search" method="get" id="searchform" action="http://localhost/kleo/">
    		
    		<div class="input-group">
    			<input name="s" id="s" autocomplete="off" type="text" class="ajax_s form-control input-sm" value="" placeholder="Search this category only" style="opacity: 1;">
    	<input type="hidden" value="32" name="cat" id="specificcat" />
    			<span class="input-group-btn">
    	            <input type="submit" value="Search" id="searchsubmit" class="button">
    			</span>
    		</div>
    	
    	</form></div>');
    
    }
    add_shortcode( 'sq-cat-search', 'custom_shortcode_sq_cat_search' );

    You will again need to edit the category ID and placeholder text. To use this you will need to enter the below shortcode in your desired location

    [sq-cat-search]

    If you need to change the shortcode name please do so on the last line of the example where you see ‘sq-cat-search’

    Thanks,

    Kieran

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    If you like the theme or the support you've received please consider leaving us a review on Themeforest!

    Custom development requests can be sent to dev@seventhqueen.com, one of the development team will be happy to discuss your needs.

Viewing 2 posts - 1 through 2 (of 2 total)

The forum ‘General questions’ is closed to new topics and replies.

Log in with your credentials

Forgot your details?