Getting search on the same page
-
Hi,
So I’ve got this search filter thing but I want the search results to appear on the same as the filter is on. However it keeps taking me to a separate search page to show the results.I think I just need to get the form action to be the current url or a certain page url or permalink.
<form action="https://localhost/siennahomes_www/property-search-sienna/>
ideally I would like it to be
<form action="https://localhost/siennahomes_www/home-designs/>
I’ve tried putting in an absolute link to test but it appears to be overwritten by a php function. It constantly stays at
<form action="https://localhost/siennahomes_www/property-search-sienna/>
no matter how much I try.The bits of code in the templates are:
Advanced-search
<?php global $theme_search_url; $theme_search_url = get_option('theme_search_url'); global $theme_search_fields; $theme_search_fields= get_option('theme_search_fields'); if( !empty($theme_search_url) && !empty($theme_search_fields) && is_array($theme_search_fields) ): ?> <section class="advance-search "> <?php $home_advance_search_title= get_option('theme_home_advance_search_title'); if(!empty($home_advance_search_title)){ ?><h3 class="search-heading"><i class="fa fa-search"></i><?php echo $home_advance_search_title; ?></h3><?php } get_template_part('template-parts/search-form'); ?> </section> <?php endif; ?>
search-form
<?php global $theme_search_fields; if( !empty($theme_search_fields) ): ?> <div class="as-form-wrap"> <form class="advance-search-form clearfix" action="<?php global $theme_search_url; echo $theme_search_url; ?>" method="get"> <?php if ( in_array ( 'keyword-search', $theme_search_fields ) ) { ?> <div class="option-bar large"> <label for="keyword-txt"><?php _e('Keyword', 'framework'); ?></label> <input type="text" name="keyword" id="keyword-txt" value="<?php echo isset ( $_GET['keyword'] ) ? $_GET['keyword'] : ''; ?>" placeholder="<?php _e('Any', 'framework'); ?>" /> </div> <?php } if ( in_array ( 'property-id', $theme_search_fields ) ) { ?> <div class="option-bar large"> <label for="property-id-txt"><?php _e('Property ID', 'framework'); ?></label> <input type="text" name="property-id" id="property-id-txt" value="<?php echo isset($_GET['property-id'])?$_GET['property-id']:''; ?>" placeholder="<?php _e('Any', 'framework'); ?>" /> </div> <?php } if( in_array ( 'location', $theme_search_fields ) ) { /* number of locations chosen from theme options */ $location_select_count = intval( get_option( 'theme_location_select_number' ) ); if( ! ( $location_select_count > 0 && $location_select_count < 5) ){ $location_select_count = 1; } /* global variable that contains location select boxes names */ global $location_select_names; /* Default location select boxes titles */ $location_select_titles = array( __( 'Main Location', 'framework' ), __( 'Child Location', 'framework' ), __( 'Grand Child Location', 'framework' ), __( 'Great Grand Child Location', 'framework' ) ); /* override select boxes titles based on theme options data */ for ( $i = 1; $i <= 4; $i++ ) { $temp_location_title = get_option( 'theme_location_title_' . $i ); if( $temp_location_title ) { $location_select_titles[ $i - 1 ] = $temp_location_title; } } /* Generate required location select boxes */ for( $i=0; $i < $location_select_count; $i++ ) { ?> <div class="option-bar large"> <label for="<?php echo $location_select_names[$i]; ?>"><?php echo $location_select_titles[$i] ?></label> <span class="selectwrap"> <select name="<?php echo $location_select_names[$i]; ?>" id="<?php echo $location_select_names[$i]; ?>" class="search-select"></select> </span> </div> <?php } /* important action hook - related JS works based on it */ do_action( 'after_location_fields' ); } if ( in_array ( 'status', $theme_search_fields ) ) { ?> <div class="option-bar large"> <label for="select-status"><?php _e('Property Status', 'framework'); ?></label> <span class="selectwrap"> <select name="status" id="select-status" class="search-select"> <?php advance_search_options('property-status'); ?> </select> </span> </div> <?php } if ( in_array ( 'type', $theme_search_fields ) ) { ?> <div class="option-bar large"> <label for="select-property-type"><?php _e('Property Type', 'framework'); ?></label> <span class="selectwrap"> <select name="type" id="select-property-type" class="search-select"> <?php advance_hierarchical_options('property-type'); ?> </select> </span> </div> <?php } if ( in_array( 'min-beds', $theme_search_fields ) ) { ?> <div class="option-bar small"> <label for="select-bedrooms"><?php _e('Min Beds', 'framework'); ?></label> <span class="selectwrap"> <select name="bedrooms" id="select-bedrooms" class="search-select"> <?php numbers_list('bedrooms'); ?> </select> </span> </div> <?php } if ( in_array ( 'min-baths', $theme_search_fields ) ) { ?> <div class="option-bar small"> <label for="select-bathrooms"><?php _e('Min Baths', 'framework'); ?></label> <span class="selectwrap"> <select name="bathrooms" id="select-bathrooms" class="search-select"> <?php numbers_list('bathrooms'); ?> </select> </span> </div> <?php } if ( in_array( 'min-max-price', $theme_search_fields ) ) { ?> <div class="option-bar small price-for-others"> <label for="select-min-price"><?php _e('Min Price', 'framework'); ?></label> <span class="selectwrap"> <select name="min-price" id="select-min-price" class="search-select"> <?php min_prices_list(); ?> </select> </span> </div> <div class="option-bar small price-for-others"> <label for="select-max-price"><?php _e('Max Price', 'framework'); ?></label> <span class="selectwrap"> <select name="max-price" id="select-max-price" class="search-select"> <?php max_prices_list(); ?> </select> </span> </div> <div class="option-bar small price-for-rent hide-fields"> <label for="select-min-price"><?php _e('Min Price', 'framework'); ?></label> <span class="selectwrap"> <select name="min-price" id="select-min-price-for-rent" class="search-select" disabled="disabled"> <?php min_prices_for_rent_list(); ?> </select> </span> </div> <div class="option-bar small price-for-rent hide-fields"> <label for="select-max-price"><?php _e('Max Price', 'framework'); ?></label> <span class="selectwrap"> <select name="max-price" id="select-max-price-for-rent" class="search-select" disabled="disabled"> <?php max_prices_for_rent_list(); ?> </select> </span> </div> <?php } if ( in_array ( 'min-max-area', $theme_search_fields ) ) { $area_unit = get_option("theme_area_unit"); ?> <div class="option-bar small"> <label for="min-area"><?php _e('Min Area', 'framework'); ?> <span><?php if($area_unit){ echo "($area_unit)"; } ?></span></label> <input type="text" name="min-area" id="min-area" pattern="[0-9]+" value="<?php echo isset($_GET['min-area'])?$_GET['min-area']:''; ?>" placeholder="<?php _e('Any', 'framework'); ?>" title="<?php _e('Please only provide digits!','framework'); ?>" /> </div> <div class="option-bar small"> <label for="max-area"><?php _e('Max Area', 'framework'); ?> <span><?php if($area_unit){ echo "($area_unit)"; } ?></span></label> <input type="text" name="max-area" id="max-area" pattern="[0-9]+" value="<?php echo isset($_GET['max-area'])?$_GET['max-area']:''; ?>" placeholder="<?php _e('Any', 'framework'); ?>" title="<?php _e('Please only provide digits!','framework'); ?>" /> </div> <?php } ?> <div class="option-bar"> <input type="submit" value="<?php _e('Search', 'framework'); ?>" class=" real-btn btn"> </div> <?php if ( in_array ( 'features', $theme_search_fields ) ) { /* all property features terms */ $all_features = get_terms( 'property-feature' ); $required_features_slugs = array(); if ( isset( $_GET['features'] ) ) { $required_features_slugs = $_GET['features']; } $features_count = count ( $all_features ); if ( $features_count > 0 ) { ?> <div class="clearfix"></div> <div class="more-option-trigger"> <a href="#"> <i class="fa <?php echo ( count( $required_features_slugs ) > 0 )? 'fa-minus-square-o': 'fa-plus-square-o'; ?>"></i> <?php _e( 'Looking for certain features', 'framework' ); ?> </a> </div> <div class="more-options-wrapper clearfix <?php echo ( count( $required_features_slugs ) > 0 )? '': 'collapsed'; ?>"> <?php foreach ($all_features as $feature ) { ?> <div class="option-bar"> <input type="checkbox" id="feature-<?php echo $feature->slug; ?>" name="features[]" value="<?php echo $feature->slug; ?>" <?php if ( in_array( $feature->slug, $required_features_slugs ) ) { echo 'checked'; } ?> /> <label for="feature-<?php echo $feature->slug; ?>"><?php echo ucwords( $feature->name ); ?> <small>(<?php echo $feature->count; ?>)</small></label> </div> <?php } ?> </div> <?php } } ?> </form> </div> <?php endif; ?>
home-designs page
<?php /* * Template Name: home designs test */ get_header(); /* Theme Home Page Module */ $theme_search_module = get_option('theme_search_module'); ?> <!-- Content --> <div class="container contents"> <div class="row"> <div class="span12"> <!-- Main Content --> <div class="main"> <?php /* Advance Search Form */ get_template_part('template-parts/advance-search-test'); ?> <section class="property-items"> <div class="search-header"> <?php get_template_part('template-parts/sort-controls'); ?> </div> <div class="property-items-container clearfix"> <?php /* List of Properties on Homepage */ $number_of_properties = intval(get_option('theme_properties_on_search')); if(!$number_of_properties){ $number_of_properties = 4; } $search_args = array( 'post_type' => 'property', 'posts_per_page' => $number_of_properties, 'paged' => $paged ); // Apply Search Filter $search_args = apply_filters('real_homes_search_parameters',$search_args); $search_args = sort_properties($search_args); $search_query = new WP_Query( $search_args ); if ( $search_query->have_posts() ) : $post_count = 0; while ( $search_query->have_posts() ) : $search_query->the_post(); /* Display Property for Search Page */ get_template_part('template-parts/property-for-home'); $post_count++; if(0 == ($post_count % 2)){ echo '<div class="clearfix"></div>'; } endwhile; wp_reset_query(); else: ?><div class="alert-wrapper"><h4><?php _e('No Properties Found!', 'framework') ?></h4></div><?php endif; ?> </div> <?php theme_pagination( $search_query->max_num_pages); ?> </section> </div><!-- End Main Content --> </div> <!-- End span12 --> </div><!-- End row --> </div><!-- End content --> <?php get_footer(); ?>
I suspect the culprit is this line:
$theme_search_url = get_option('theme_search_url');
- The topic ‘Getting search on the same page’ is closed to new replies.