How to implement custom search with input fields?

I want to implement a search form like this: Loan Form

In my theme I have a custom post type called Data with the Year and Money custom fields.

Read More

I googled a lot but can’t find a way to submit the user inputs to a place from where I can use WP_Query to populate the search result.

So, how to take user input from a form and use it to create a result page in WordPress?

And also please someone explain how the WordPress ?s= query works.

Related posts

Leave a Reply

1 comment

  1. Creating custom search is not the easiest of tasks for beginners. You will need templates search.php and searchform.phpView Codex. You can then edit searchform.php and add any fields you need. When the user submits the form it will also add any extra fields you have – so your search url may look something like this /?s=1000&num=5&type=years (using the Loan Form example given in the question).

    Once you have your form set up and submitting correctly you can use a hook such as pre_get_postsView Codex combined with some Conditional Tags to test if is_search() then you can grab your extra inputs: $_GET['num'] $_GET['type'] and modify your query based on the values given.

    That’s the gist of it anyway.