Skip to content

Instantly share code, notes, and snippets.

@g-maclean
Created February 18, 2026 16:13
Show Gist options
  • Select an option

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

Select an option

Save g-maclean/7ae9c685a9f64f81d591ffca16a4ef61 to your computer and use it in GitHub Desktop.
Property Hive - Properties Shortcode - Maintain sorting by price when meta_key is defined in atts
// currently, when meta_key is used in the properties shortcode it effectively remvoes the price sorting, this restores it
add_filter( 'propertyhive_shortcode_properties_query', function( $args, $atts ) {
// Only apply when shortcode is filtering investment properties
if (
empty( $atts['meta_key'] ) ||
$atts['meta_key'] !== '_investment_property'
) {
return $args;
}
if ( empty( $args['meta_query'] ) ) {
$args['meta_query'] = [];
}
$args['meta_query'][] = [
'key' => '_investment_property',
'compare' => 'EXISTS',
];
$args['meta_key'] = '_price_actual';
$args['orderby'] = 'meta_value_num';
$args['order'] = 'DESC';
return $args;
}, 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment