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.
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.
Creating custom search is not the easiest of tasks for beginners. You will need templates
search.php
andsearchform.php
– View Codex. You can then editsearchform.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_posts
– View Codex combined with some Conditional Tags to testif 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.