• I need some guidance as it relates to creating a custom search form that will be a part of a page template. What I need is the following:

    Text field that searches a specific tag
    Text field that searches another specific tag
    Text field that searches post titles in a specific category

    All three don’t need to be filled out, just one. Autocomplete would be nice, but for now I’m just trying something basic. Thanks in advance for the help!

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    Your search form can submit back to the same page template. If the template loads for a GET request, you just display the form. The form method will be POST, so any POST request means your template will show the results of a custom WP_Query.

    Some code will be required to build the correct argument array based on which form fields were supplied. For tag searches, add tag query parameters.

    Oddly, though a title search is a fairly simple SQL query, it is a bit convoluted with WP_Query. You can start with the search parameter. But this searches both the title and content columns of the posts table. To not search content, you need to hook the ‘posts_where_paged’ filter and remove the content column portion of the WHERE clause.

    You will probably need to add in other arguments to build a complete query, such as post type, status, and pagination parameters.

Viewing 1 replies (of 1 total)
  • The topic ‘Need some help creating a simple, custom search form’ is closed to new replies.