CPT Search Form with Taxonomy filter & Or


I currently use the form below :

<form role="search" method="get" class="search-form" action="<?php echo home_url( '/' ); ?>">

        <input type="search" class="search-field" placeholder="<?php echo esc_attr_x( 'Type Business or Town', 'placeholder' ) ?>" value="<?php echo get_search_query() ?>" name="s" title="<?php echo esc_attr_x( 'Search for:', 'label' ) ?>" />

        <input type="text" value="<?php echo get_query_var('location'); ?>" name="location" id="location" class="headersearch location" placeholder="<?php esc_attr_e( 'Enter your county..', 'search-cust' ); ?>" />

        <input type="hidden" name="post_type" value="business" />
        <input type="submit" class="button radius tiny success" style="width: 100%;" value="<?php esc_attr_e( 'Search...', 'search-cust' ); ?>" />

I also have this in functions.php :

    function custom_cpt_search( $query ) {
       if ( is_search() && $query->is_main_query() && $query->get( 's' ) ){
            $query->set('post_type', array('business'));
        return $query;
add_filter('pre_get_posts', 'custom_cpt_search');

Ideally id like to have the second input as a drop-down taxonomy list instead of a type-in input, Ideally listing ALL categories in the taxonomy instead of only categories with posts in them. With the first dropdown item being a placeholder such as “Select your county”.

Edited to make clearer, and remove part of the question I have resolved.

, , Randomer11 6 years 2017-10-14T10:21:35-05:00 0 Answers 96 views 0

Leave an answer