The change required in home page search form: For example, if I search for an investment advisor in Bengaluru,
right now it shows the URL: https://finvizer.com/?swoof=1&post_type=product&product_cat=investment-advisor-bengaluru
This need to change to: https://finvizer.com/investment-advisers-in-bengaluru/
Code: First one is in functions.php
<div class="header-search-form">
<form role="search" method="get" action="<?php echo esc_url( home_url( '/' ) );
now in this peice of code, method is get and what action doing is: calling the home url of the website(i.e. http://finvizer.com) and onsubmit the function is called serch_validate_home(), which is working fine.
?>" name="serchvalidformhome" id="serchvalidformhome" onsubmit="return serch_validate_home();">
<input type="hidden" name="swoof" id="swoofhm" value="1" />
<input type="hidden" name="post_type" id="post_typehm" value="product" />
this inputs are form a plugin "woocommerce" which comes in url, because of this peice of code website is landing to https://finvizer.com/?swoof=1&post_type=product&product_cat=investment-advisor-bengaluru but i wanted page to be redirected https://finvizer.com/investment-advisers-in-bengaluru/
I have made them comment and tried to run and the result was http://www..finvizer.com/?product_cat=
<div class="i-would-lik-cls">
<?php $terms = get_terms( 'locationfilter',array('hide_empty' => 0, 'orderby' => 'ASC')); ?>
<span class="srch-frm-home-temp-one">I need a</span>
<select id="servicehm" style="width:100%">
<option value="">Choose a Service...</option>
<option value="financial-planner-">Financial Planner</option>
<option value="investment-advisor-">Investment Adviser</option>
<option value="wealth-advisor-">Wealth Adviser</option>
</select >
</div>
<span class="srch-frm-home-temp-two">in</span>
<div class="annual-incom-cls">
<select id="locationfilterhm" style="width:100%" ">
<option value="">Location</option>
<option value="ahmedabad">Ahmedabad</option>
<option value="bengaluru">Bengaluru</option>
<option value="chennai">Chennai</option>
<option value="delhi">Delhi</option>
<option value="gurgaon">Gurgaon</option>
<option value="hyderabad">Hyderabad</option>
<option value="indore">Indore</option>
<option value="kolkata">Kolkata</option>
<option value="kochi">Kochi</option>
<option value="mumbai">Mumbai</option>
<option value="pune">Pune</option>
<option value="surat">Surat</option>
</select >
</div>
so from here, I saw there is one more input product cat, I changed it nothing(input name="") than website was redirected to https://finvizer.com/?
<input name="product_cat" id="product_cathm" value="" type="hidden" />
<div class="prod-serh">
<button type="submit">search</button>
</div>
</form>
</div>
</div>
</div>
<div style="clear:both;"></div>
<?php
$ReturnString = ob_get_contents(); ob_end_clean(); return $ReturnString;
}
The second one is in footer.php it's a javascript code in footer.php. This function is called by functions.php Here two variable are taking value from the form, the service value is in ser and location one is in loct.
function serch_validate_home(){
var ser = jQuery("#servicehm").val();
var loct = jQuery("#locationfilterhm").val();
if( ser!='' && loct!=''){
in this srch variable, I have already placed "in-" . it made the srch variable vale what we want (i.e. financial-planner-in-bengaluru). but it's not working without those two HTML embedded inputs which I mentioned above. And when I try with them the page gets crashed.
var srch =ser+loct;
jQuery("#product_cathm").val(srch);
document.serchvalidformhome.submit();
}
return false;
}
p.s. this code is written by another developer, which the owner has no contact with, I have been asked to redirect the page on a different link. I tried to go through each and every step as per my knowledge but got stuck. I was able to remove everything from the link and was able to redirect to https://finvizer.com/? but how should I place that srch varable instead of that "?"