Adding a Search form to a WordPress Index page and to search by ID

Description

Copy the code and paste it anywhere. Change ID 20 to the id of the category you want to filter

PHP Source Code

                        
                          <form role="search" method="get" class="search-form" action="<?php echo home_url('/'); ?>">
    <label>
        <span class="screen-reader-text"><?php echo _x('Search for:', 'label'); ?></span>
        <input type="search" class="search-field" placeholder="<?php echo esc_attr_x('Search …', 'placeholder'); ?>" value="<?php echo get_search_query(); ?>" name="s" />
    </label>
    <input type="hidden" name="cat" value="20">
    <button type="submit" class="search-submit"><?php echo esc_attr_x('Search', 'submit button'); ?></button>
</form>                        
                        


Post Categories