Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save celticwebdesign/5928bcbd4c6a581ee5f90cf615e28448 to your computer and use it in GitHub Desktop.
Save celticwebdesign/5928bcbd4c6a581ee5f90cf615e28448 to your computer and use it in GitHub Desktop.
// http://www.wpbeginner.com/wp-tutorials/how-to-use-shortcodes-in-your-wordpress-sidebar-widgets/
add_filter('widget_text','do_shortcode');
add_shortcode('shortcode_find_restaurant', 'shortcode_find_restaurant');
function shortcode_find_restaurant() {
$terms = get_terms( array(
'taxonomy' => 'towns-restaurant',
'hide_empty' => false,
) );
if ( $terms && ! is_wp_error( $terms ) ) :
$output = "<select name=\"towns-restaurant\" class=\"taxonomy\" onchange=\"if (this.options[selectedIndex].value != '') location.href=this.options[selectedIndex].value\">";
$output .= "<option value=''>Select a town</option>";
$draught_links = array();
foreach ( $terms as $term ) {
if( $term->count > 0 ) {
$term_link = get_term_link( $term );
$draught_links[] = $term->name;
$output .= "<option value='".$term_link."'>".$term->name."</option>";
}
}
$on_draught = join( " ", $draught_links );
$output .= "</select>";
// search
$output .= '
<form class="search clear" method="get" action="'.home_url().'" role="search">
<div class="left">
<input class="search-input" type="search" name="s" placeholder="Search Restaurants">
</div>
<div class="right">
<button class="search-submit transition" type="submit" role="button">GO</button>
</div>
</form>
';
return $output;
endif;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment