0

Wordpress search results is definately not the best indexing and search function we have seen.. If adding multiple tag variables in the search in order to get a more precise result work?

For example:

Default search query: www.example.com/?s=kidsbook

What if we spiced it up a bit adding: in the search some more tags that the results must have (for example female author and bestseller). So that only post results of kidsbook AND from those results only the best sellers of female authors.

would the bellow example work?

www.example.com/?s=kidsbook&tag=femaleauthor&tag=bestseller

Would the search accept both tags?

Last question would this type of search cause a much greater load on the server?

Thanks for your answers.

0

Add a new input to the form, the name is key, you can easily access query vars that match a paremeter supporter by WP_Query using the function get_query_var.

For example, you could try to generate an URL like this:

http://example.com/?s=test&tag=5-personas,4-personas

And with get_query_var(tag), you get the values, and the you create a custom WP_Query using that parameters.

$query = new WP_Query(
 array(
    's' => get_query_var('s'), 
    'tag' => get_query_var('tag')
) );

One thing you have to take into account is that can't have the same parameter twice in the URL, well, you can, but you can't use the get_query_var function to get the value.

You can use jQuery to get the selected options from a select element with the multipleattribute, and pass the selection to an input with the name "tag", there are other workarounds for this.

The query wont affect performance that much.

I hope this gives you and idea of what to do.

| improve this answer | |
  • Thank you for your answer Tomas, sadly I cant do that as I need to have it in a multiple selection. If I just add this: www.example.com/?s=kidsbook&tag=femaleauthor&tag=bestseller would it be executed correctly by the server/wp engine? – Jack Stanson Sep 27 '14 at 10:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.