Created
March 7, 2017 16:47
-
-
Save celticwebdesign/15b97030b1a422a12fd8d1d3d337045f 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_accommodation', 'shortcode_find_accommodation'); | |
function shortcode_find_accommodation() { | |
$terms = get_terms( array( | |
'taxonomy' => 'towns-accommodation', | |
'hide_empty' => false, | |
) ); | |
if ( $terms && ! is_wp_error( $terms ) ) : | |
$output = "<select name=\"towns-accommodation\" 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