I want to search post by specific keyword. first people write whatever they seek in the search box then the form must be sent to `get_search_result.php` file but nothing happens when I submit the form it doesn’t even print my echo messages. I tried action=’get\_search\_result.php’ nothing again
I will be very grateful if someone helps me I m lost right now
searchform.php
`<?php /**`
`* Template Name: Search Page`
`*/`
`?>`
`<form method=”post” action=”<?php echo get_site_url(); ?>/get_search_result.php”>`
`<input class=”search_box” type=”search” name=”search_query” placeholder=”Search something here”>`
`<!–<input class=”send-btn” type=”submit”>–>`
`</form>`
get\_search\_result.php
`<?php`
`$search_query = $_POST[“search_query”];`
`if (isset($search_query)) {`
`echo “The word is” . $search_query;`
`$the_query = new WP_Query(array(‘s’ => $search_query));`
`while ($the_query->have_posts()) {`
`echo “Posts found”;`
`echo $the_query->the_post();`
`echo get_the_title();`
`}`
`}`
​
`else {`
`echo “Nothing to search”;`
`}`
[ad_2]
Where is that file located? You can’t include a file like that in the root, since it won’t load the necessary WP libraries – you would needed to call `require( ‘../wp-load.php’ );` first. If it’s included in the theme, then you have not got the correct URL in the ‘action’ attribute.
You will probably want to include get_header() and get_footer() in the template too.
I’m sure there would be tutorials online on how to create a custom search form + template