0

I have my search.php working fine. But I'd like to display the search results in my search.php filtered by tag_ID when is coming from another search form. I've tried several things like: wp_parse_str, new WP_Query( {parameters here} ), etc. Basically I don't know how to modify the query :(

How can I modify the main query in order to do that?

Thank you very much for your help!

PD: I've been reading several post here but no one answered my question.

This is my form code:

<form role="search" method="get" class="form-inline cp-form-search search-form" action="<?php echo esc_url( home_url( '/' ) ); ?>">
<input type="search" id="s" class="search-field form-control p-2"  placeholder="<?php echo esc_attr_x( 'Search '.$venue_archive_title, 'placeholder' ); ?>" aria-label="Search" value="<?php echo get_search_query(); ?>" name="s">
                    <input type="hidden" value="restaurants" name="venue_type_search" id="venue_type_search" />
                    <input type="hidden" value="title" name="orderby" id="orderby" />
                    <input type="hidden" value="ASC" name="order" id="order" />
                    <button type="submit"><img src="<?php echo get_template_directory_uri(); ?>/assets/images/search-white.svg" height="22"></button>
                </form>

I'd like to trigger the new query with my "venue_type_search" hidden input.

Thanks!

1
  • You can use pre_get_posts. But, "another search form" - where's the code?
    – Sally CJ
    Commented Feb 10, 2019 at 13:23

1 Answer 1

0

Filter it using pre_get_posts, like this:

function searchfilter($query) {
    if ($query->is_search && !is_admin() ) {
        if(isset($_GET['venue_type_search'])) {
            $venue_type = $_GET['venue_type_search'];

            $query->set('tag',array($venue_type));

        }       
    }
    return $query;
}
add_filter('pre_get_posts','searchfilter');
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.