Created
February 18, 2026 16:13
-
-
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
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
| // 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