After submitting the search form, the site directs to "homeurl/post-name/?s=lorem" instead of "homeurl/?s=lorem" when I have permalinks set to "%post-name%" ( not literally 'homeurl', but the domain of the site ).
When I have permalinks set to "/blog/%postname%", the search results url becomes /blog/%postname%/?s=lorem.
The action on the search form (searchform.php) is:
<?php echo get_home_url(); ?>.
If I hard code it to the home url that won't work either. It keeps appending the search query after /blog or after the post name.
I even added the following to functions.php, and it had no effect:
function search_url_rewrite () {
if ( is_search() && !empty( $_GET['s'] ) ) {
wp_redirect( home_url( '/search/' ) . urlencode( get_query_var(
's' ) ) );
exit();
}
}
add_action( 'template_redirect', ' search_url_rewrite ' );
Any idea what might be going on here and what else I can try? I already deactivated all plugins and tried it. Same story.
***** UPDATE (solution) *****
Because I am a very silly WordPresser, I had
<?php get_search_form(); ?>
wrapped in form tags
<form> </form>
I removed the tags and the problem stopped and search is working properly now.