How to 'Search Filtering' like this in WordPress

Discussion in 'Programming' started by nhed, Aug 7, 2013.

  1. #1
    Hi,
    I need your help in creating a search filter similar to one shown on this site in wordpress.
    Here is the site. You'll see the filtering options when you hover over the 'calories and diet' located right below the search bar. I have also included a screenshot here. If anyone can help me with this, I would appreciate it.
    search-filter.JPG
     
    nhed, Aug 7, 2013 IP
  2. marht

    marht Active Member

    Messages:
    142
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    58
    #2
    Hi nhed,

    You can do this with a $_GET.
    You can change the url on the submit button with Javascript for each marked category.

    For example, if I mark "Balanced" and "Low-Fat" and search for food, my url would be edamam.com/?s=food&category=12,23.

    Then you could retrieve the different category ID's by Array Exploding.

    $cats = explode(",", $_GET['category']);
    PHP:
    Then use a foreach within your mysql query.

    Hope this helps you out,

    Kind regards,

    Maarten
     
    marht, Aug 9, 2013 IP
    nhed likes this.
  3. nhed

    nhed Well-Known Member

    Messages:
    352
    Likes Received:
    31
    Best Answers:
    1
    Trophy Points:
    130
    #3
    Thank you for your help. After more digging, I am thinking of trying 'custom post types and taxonomies' and use advanced query filters. Do you think I am moving in the right direction?
     
    nhed, Aug 9, 2013 IP
  4. marht

    marht Active Member

    Messages:
    142
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    58
    #4
    Hmmm... Well what I would do is write a custom query. If the (isset($_GET['category'])) is true, then I would change my query.
    But their might be a already baked plugin for you ready in the Wordpress Plugin Directory kitchen. Here, maybe this will help you: http://wordpress.org/plugins/multiple-category-selection-widget/

    Hope this helps you out,

    Kind regards,

    Maarten
     
    marht, Aug 9, 2013 IP