Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save celticwebdesign/bc45d806d66c9f5b88fa3205d5bcabf7 to your computer and use it in GitHub Desktop.
Save celticwebdesign/bc45d806d66c9f5b88fa3205d5bcabf7 to your computer and use it in GitHub Desktop.
add_shortcode('shortcode_find_takeaway', 'shortcode_find_takeaway');
function shortcode_find_takeaway() {
$terms = get_terms( array(
'taxonomy' => 'towns-takeaway',
'hide_empty' => false,
) );
if ( $terms && ! is_wp_error( $terms ) ) :
$output = "<select name=\"towns-takeaway\" 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 ) {
$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>";
return $output;
endif;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment