Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save celticwebdesign/15b97030b1a422a12fd8d1d3d337045f to your computer and use it in GitHub Desktop.
Save celticwebdesign/15b97030b1a422a12fd8d1d3d337045f to your computer and use it in GitHub Desktop.
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