Skip to content

Instantly share code, notes, and snippets.

@propertyhive
Created October 24, 2024 15:45
Show Gist options
  • Save propertyhive/ab2190fbd3a2dcd14f1a8a1e58aff5cb to your computer and use it in GitHub Desktop.
Save propertyhive/ab2190fbd3a2dcd14f1a8a1e58aff5cb to your computer and use it in GitHub Desktop.
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