WordPress.org

Ready to get started?Download WordPress

Forums

EM Beer Manager
Search fields (5 posts)

  1. lineaymedia
    Member
    Posted 1 year ago #

    Hello.
    I am preparing a site for a beer bar and I would like to do a search in the list of beers.

    The site has about 300-400 beers and I need to create a search engine.
    How I can I create a search field or drop-down menu with the styles of the beers??

    http://wordpress.org/plugins/em-beer-manager/

  2. Erin Morelli
    Member
    Plugin Author

    Posted 1 year ago #

    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!

  3. lineaymedia
    Member
    Posted 1 year ago #

    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

  4. Erin Morelli
    Member
    Plugin Author

    Posted 1 year ago #

    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!

  5. Erin Morelli
    Member
    Plugin Author

    Posted 1 year ago #

    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!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.