Skip to content

Instantly share code, notes, and snippets.

@g-maclean
Created January 14, 2026 11:34
Show Gist options
  • Select an option

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

Select an option

Save g-maclean/c3429e45a5abf199fa7d6b2f928e6f29 to your computer and use it in GitHub Desktop.
Property Hive - [properties] shortcode with fallback
add_shortcode( 'properties_with_fallback', 'ph_properties_with_fallback' );
function ph_properties_with_fallback( $atts ) {
$atts = shortcode_atts(
array(
'primary_atts' => '',
'fallback_atts' => '',
'fallback_message' => '',
),
$atts
);
// Primary PropertyHive shortcode
$primary_shortcode = '[properties ' . $atts['primary_atts'] . ']';
$primary_output = do_shortcode( $primary_shortcode );
// Look for no-results-message string
if ( strpos( $primary_output, 'no-results-message' ) !== false ) {
$output = '';
// Optional fallback message
if ( ! empty( $atts['fallback_message'] ) ) {
$output .= '<div class="properties-fallback-message">';
$output .= wp_kses_post( wpautop( $atts['fallback_message'] ) );
$output .= '</div>';
}
// Fallback PropertyHive shortcode
$fallback_shortcode = '[properties ' . $atts['fallback_atts'] . ']';
$output .= do_shortcode( $fallback_shortcode );
return $output;
}
return $primary_output;
}
/*
* example usage:
*
[properties_with_fallback
primary_atts="department='residential-sales' address_keyword='Edinburgh'"
fallback_atts="department='residential-sales' address_keyword='Glasgow'"
fallback_message="No results available for X, here are some other properties"
]
* /
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment