Skip to content

Instantly share code, notes, and snippets.

@g-maclean
Created November 19, 2024 16:12
Show Gist options
  • Select an option

  • Save g-maclean/c54bc1a1f810c892e409ca0a3329a2b2 to your computer and use it in GitHub Desktop.

Select an option

Save g-maclean/c54bc1a1f810c892e409ca0a3329a2b2 to your computer and use it in GitHub Desktop.
PropertyHive - shortcode for displaying room counts
add_shortcode("room_counts", "output_room_counts");
function output_room_counts(){
global $property;
$bedrooms = $property->bedrooms;
$bathrooms = $property->bathrooms;
$reception_rooms = $property->reception_rooms;
$rooms= [];
if ( !empty($bedrooms) ) {
$rooms[] = $bedrooms . ' Bedroom' . ( ( $bedrooms != 1 ) ? 's' : '' );
}
if ( !empty($bathrooms) ) {
$rooms[] = $bathrooms . ' Bathroom' . ( ( $bathrooms != 1 ) ? 's' : '' );
}
if ( !empty($reception_rooms) ) {
$rooms[] = $reception_rooms . ' Reception' . ( ( $reception_rooms != 1 ) ? 's' : '' );
}
return "<div class='room_counts'>" . implode(', ', $rooms) . "</div>";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment