Created
October 24, 2024 15:45
-
-
Save propertyhive/ab2190fbd3a2dcd14f1a8a1e58aff5cb to your computer and use it in GitHub Desktop.
This file contains 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/allonmarketpropertyquerynoordering ', 'query_but_random', 99 ); | |
function query_but_random( $query ) | |
{ | |
PH()->query->property_query( $query ); | |
$query->set( 'orderby', 'rand' ); | |
// Set the custom post type | |
$query->set( 'post_type', [ 'property' ] ); | |
// ensure a department is set as not set by default from property_query | |
$meta_query = $query->get('meta_query'); | |
$new_meta_query = $meta_query; | |
$department_found = false; | |
foreach ( $meta_query as $key => $value ) | |
{ | |
if ( isset($value['key']) && $value['key'] == '_department' ) | |
{ | |
} | |
else | |
{ | |
$new_meta_query[] = $meta_query; | |
} | |
} | |
$query->set( 'meta_query', $new_meta_query ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment