Created
March 7, 2017 16:46
-
-
Save celticwebdesign/bc45d806d66c9f5b88fa3205d5bcabf7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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