I have a few dropdown select option in my wordpress sidebar:

enter image description here

Whenever a user selects an option from any of the dropdown, they are directed to the search result page:

http://mywebsite/wp/?post_type=post&taxonomy=category&terms=29&search_type=or&order=title

The 29 is the Tag that is searches for which is what the user selected.

I am doing that functionality with JQuery:

$('select').on('change', function () {
    var url = $(this).val(); // get selected value
    if (url) { // require a URL
        window.location = "http://mywebsite/wp/?post_type=post&taxonomy=category&terms=" + url + "&search_type=or&order=title"; // redirect
    }
    return false;
});

I was trying to, instead of the above JQuery to have this:

$("#search").click(function(){
    var k = $("#mtsw-form-children-term-ids-10 option:selected").val();
    var m = $("#mtsw-form-children-term-ids-13 option:selected").val();
    var o = $("#mtsw-form-children-term-ids-11 option:selected").val();
    alert("Location: " + k + "\nSpecialty: " + m + "\nPhysician: " + o);
            //window.location = ; //SEARCH BASED ON LOCATION, and/or SPECIALTY, and/or PHYSICIAN tags
});

I am using the Multi-Term-Selection widget for the dropdown.

How would I know if I am able to accomplish that search? I am new to WordPress so I am trying to understand the starting point.

1 Answer
1

Firstly, stop repurposing categories and tags, instead use custom taxonomies. This will give you:

  • archives and listings
  • URLs to view each taxonomy
  • User interfaces that match the names

I would personally have chosen a physician custom post type with specialty and location taxonomies. However I am assuming this is a way of filtering down posts so working off of this assumption, register these taxonomies:

  • location
  • specialty
  • physician

Next, throw your javascript away, and implement your interface as a form.

<form action="" method="GET">

With 3 select inputs with these names:

  • location
  • specialty
  • physician

The options in these select inputs will have values matching the slugs of each term.

For additional parameters such as order, put them in an input of type hidden.

Finally add a submit button and label it ‘search’. You should now have a non-js version of what you wanted.

You should also have these archives:

  • example.com/location/example
  • example.com/specialty/example
  • example.com/physician/example

And these templates available to you:

  • taxonomy-location.php
  • taxonomy.php
  • archive.php

etc for each taxonomy, refer to the template hierarchy diagram when deciding which one you wish to implement.

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *