Support » Plugin: EM Beer Manager » Search fields

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Erin Morelli

    (@erinmorelli)

    Hi lineaymedia,

    I’m not sure exactly how you’re creating the search engine, but the beer styles are stored in the WordPress database as a custom taxonomy called “embm_style” – if you’re able to hook into that, you could generate a dropdown menu. Can you give me more details on how you’re building the search?

    Thanks!

    Hello ErinMorelli.
    I put this in my functions.php

    function get_terms_dropdown($taxonomies, $args){
        $myterms = get_terms($taxonomies, $args);
        $output ="<select name='embm_style'>";
        $output .="<option value='#'>Please select a style</option>";
        foreach($myterms as $term){
            $root_url = get_bloginfo('url');
            $term_taxonomy=$term->taxonomy;
            $term_slug=$term->slug;
            $term_name =$term->name;
            $link = $term_slug;
            $output .="<option value='".$link."'>".$term_name."</option>";
        }
        $output .="</select>";
    return $output;
    }

    then I put the following code in my template to get the dropdown menu to select a style of beer.

    <form action="<?php bloginfo('url'); ?>" method="get">
    				<p>Search for a style from the drop down menu:</p>
    				<?php
    				$taxonomies = array('embm_style');
    				$args = array('orderby'=>'name','hide_empty'=>true);
    				$select = get_terms_dropdown($taxonomies, $args);
    
    				$select = preg_replace("#<select([^>]*)>#", "<select$1 onchange='return this.form.submit()'>", $select);
    				echo $select;
    				?>
    				<div><input type="submit" value="Go" /></div>
    			</form>

    The problem is that the search result does not filter styles and returns the entire list of beers without the filter.
    Can you help me

    Plugin Author Erin Morelli

    (@erinmorelli)

    Hi lineaymedia,

    Try these two edits:

    In your functions.php code change

    $output .="<option value='#'>Please select a style</option>";

    to

    $output .="<option value=''>Please select a style</option>";

    (removing the hashtag)

    Then under your form code change

    $args = array('orderby'=>'name','hide_empty'=>true);

    to

    $args = array('orderby'=>'name','hide_empty'=>false);

    and add a name=”submit” to the input

    <input type="submit" name="submit" value="Go" />

    Let me know if those tweaks work. If not, I can better test it out on my local development workspace later today.

    Thanks!

    Plugin Author Erin Morelli

    (@erinmorelli)

    Hi lineaymedia,

    Just wanted to follow up with you – did any of my previous suggestions work, or were you still having trouble with your custom search?

    Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Search fields’ is closed to new replies.