• Hi guys, my goal is to show in homepage a search form with 6-7 fields (text, number, checkbox type) that return a page with the posts the respect the conditions, so the posts that have the custom fields valued with the user inputs.
    I tried to look for free plugins, but it seems there aren’t good.
    I use Elementor Pro with Hello theme.
    Can you guide me please step by step to implement this functionality? Please also to modify core files if needed or set a child theme.
    Thanks very much.

    • This topic was modified 4 years, 6 months ago by Jan Dembowski.
Viewing 6 replies - 1 through 6 (of 6 total)
  • Moderator bcworkz

    (@bcworkz)

    Please also to modify core files if needed or set a child theme.

    Do not even think about modifying core files, please. No good can come from it and there is never any need to do so. Modifying WordPress can be done through action and filter hooks and custom templates. A child theme is a great way to contain such modifications. More on child themes:
    https://developer.www.ads-software.com/themes/advanced-topics/child-themes/

    Thread Starter ita10

    (@ita10)

    @corrinarusso thanks, I had seen this but I didn’t like. Maybe I have not understood how it works. I’ll try again.

    @bcworkz ok, thanks for the subggestions. But once I have a child theme how can I do to realize that search form?

    @ita10

    The child is simply to add functionality to WordPress without modifying the core. You use it to extend functionality. This is important for a few reasons – namely to allow WordPress and themes to update with different versions and patches without impacting your code in the child theme.

    Moderator bcworkz

    (@bcworkz)

    There’s many ways to implement a search form. This is merely one suggestion. Create a function that outputs search form content. It’s declaration can go in child functions.php.

    Check you parent theme’s template code for any possible hooks you might be able to use to be able to call your form function. There’s unlikely to be a do_action() call right on a template, but check the source code for functions called near where you want your form to appear.

    If no hooks are apparent, you’ll need to modify templates. Copy the template from where the output should occur to the child and insert your form’s function call. This is typically either header.php or sidebar.php, but is theme dependent, YMMV.

    You can have your form submit to a custom search results page. Or let the default “s” query var for the search term remain and modify the default query through the “pre_get_posts” action. Unless the form is really simple, I’d use a custom results page.

    For a custom page, either create a custom page template or submit through /wp-admin/admin-post.php, in which case the results output is managed through a specific action hook. The hook is in part composed from a hidden field in your form named “action”. This is similar to how WP Ajax works, except no JS is involved.

    The page code validates and sanitizes form data. There should also be a nonce submitted as a hidden field that is validated now. Use the data to compose a custom WP_Query and loop through the results in the usual manner. You cannot use the usual pagination functions with custom queries. You should use paginate_links() instead of what your theme normally uses.

    Thread Starter ita10

    (@ita10)

    Thanks a lot.
    The problem is that I don’t know what code to use.
    In the meantime I found Searh&Filter plugin that permit me to filter taxonomies.
    It’s a very smart plugin, but with some format customization with the css I reached more or less what I was looking for.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Search form in Home page with multiple custom fields in input’ is closed to new replies.