Create separate search forms for products, posts types and posts in WordPress

Create separate search forms for products, posts types and posts in WordPress

I will show you how you can add transparent logo or icon watermark using php script on an image(s) and save result image(s). You can align logo or icon using perimeters which are used in imagecopy() php function `` anywhere in wordpress templates. Sometimes client want to get search record from particular categories or taxonomies. i.e. products, custom post types, blogs. You can do this by the following code.

Search records from all

<form method="get" class="search-form" action="<?php echo site_url(); ?>">
    <input type="text" class="search-post" name="s" placeholder="<?php echo esc_attr_x( 'Search Posts...', 'placeholder' ) ?>" value="<?php echo get_search_query() ?>" />
    <button type="submit" class="search-submit">Search</button> 
</form>

Search records from custom posts types software and books only

<form method="get" class="search-form" action="<?php echo site_url(); ?>">
    <input type="text" class="search-post" name="s" placeholder="<?php echo esc_attr_x( 'Search Posts...', 'placeholder' ) ?>" value="<?php echo get_search_query() ?>" />
    <input type="hidden" name="post_type[]" value="software" />
    <input type="hidden" name="post_type[]" value="books" />
    <button type="submit" class="search-submit">Search</button> 
</form>

Search records from products only

Also Read: Get all categories from custom post type in WordPress
<form method="get" class="search-form" action="<?php echo site_url(); ?>">
    <input type="text" class="search-product" name="s" placeholder="<?php echo esc_attr_x( 'Search Products...', 'placeholder' ) ?>" value="<?php echo get_search_query() ?>" />
    <input type="hidden" value="product" name="post_type" id="post_type" />
    <button type="submit" class="search-submit">Search</button> 
</form>

Also Read: Create multiple headers, footers, sidebars for different templates in WordPress

I will show you how you can add transparent logo or icon watermark using php script on an image(s) and save result image(s). You can align logo or icon using perimeters which are used in imagecopy() php function `` anywhere in wordpress templates. Sometimes client want to get search record from particular categories or taxonomies. i.e. products, custom post types, blogs. You can do this by the following code.

Search records from all

<form method="get" class="search-form" action="<?php echo site_url(); ?>">
    <input type="text" class="search-post" name="s" placeholder="<?php echo esc_attr_x( 'Search Posts...', 'placeholder' ) ?>" value="<?php echo get_search_query() ?>" />
    <button type="submit" class="search-submit">Search</button> 
</form>

Search records from custom posts types software and books only

<form method="get" class="search-form" action="<?php echo site_url(); ?>">
    <input type="text" class="search-post" name="s" placeholder="<?php echo esc_attr_x( 'Search Posts...', 'placeholder' ) ?>" value="<?php echo get_search_query() ?>" />
    <input type="hidden" name="post_type[]" value="software" />
    <input type="hidden" name="post_type[]" value="books" />
    <button type="submit" class="search-submit">Search</button> 
</form>

Search records from products only

Also Read: Get all categories from custom post type in WordPress
<form method="get" class="search-form" action="<?php echo site_url(); ?>">
    <input type="text" class="search-product" name="s" placeholder="<?php echo esc_attr_x( 'Search Products...', 'placeholder' ) ?>" value="<?php echo get_search_query() ?>" />
    <input type="hidden" value="product" name="post_type" id="post_type" />
    <button type="submit" class="search-submit">Search</button> 
</form>

Also Read: Create multiple headers, footers, sidebars for different templates in WordPress

Please let me know what your thoughts or comments are on this article. If you have any suggestion or found any mistake in this article then please let us know.

Latest Comments

Jhilmil
Jhilmil
27 Dec 2020

Before this I had installed search plugin to get search products and custom post types functionality, which slow down my website. I have deactivated the plugin and use custom code as your given in above example.

Add your comment

Close