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="http://localhost/siennahomes_www/property-search-sienna/>
ideally I would like it to be
<form action="http://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
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;
?>
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(); ?>
search-form:
<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>
I suspect the culprit is this line on the advanced search page:
$theme_search_url = get_option('theme_search_url');