Created
August 9, 2026 22:01
-
-
Save g-maclean/67e3bcbfdcab658a2f3c61a3bc4f1c60 to your computer and use it in GitHub Desktop.
Property Hive - Elementor - Show only properties of a custom department with a parent/child relation
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
| add_action( | |
| 'elementor/query/plotspropertyquery', | |
| 'elementor_query_plots' | |
| ); | |
| function elementor_query_plots( $query ) { | |
| $current_property_id = get_queried_object_id(); | |
| if ( ! $current_property_id ) { | |
| return; | |
| } | |
| $reference_number = get_post_meta( | |
| $current_property_id, | |
| '_reference_number', | |
| true | |
| ); | |
| // Don't return anything if the current property | |
| // doesn't have a reference number. | |
| if ( empty( $reference_number ) ) { | |
| $query->set( 'post__in', array( 0 ) ); | |
| return; | |
| } | |
| $query->set( 'post_type', 'property' ); | |
| $query->set( 'meta_query', array( | |
| 'relation' => 'AND', | |
| // Only properties in the Plots department. | |
| array( | |
| 'key' => '_department', | |
| 'value' => 'plots', | |
| 'compare' => '=', | |
| ), | |
| // Parent development must match the current | |
| // property's reference number. | |
| array( | |
| 'key' => '_parent_development', | |
| 'value' => $reference_number, | |
| 'compare' => '=', | |
| ), | |
| ) ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment