I have a custom post type 'properties' which has a checkbox field (fieldname 'property_status') with the options 'rent : For rent' and 'sale : For sale' (value : label). I also have a page where I want to list all the properties that are for sale, so there I have added the posts widget and gave the query the ID 'for-sale'. I checked the custom query documentation at https://developers.elementor.com/custom-query-filter/ and in my child theme's functions.php I have added the following lines:
add_action( 'elementor/query/for-sale', function( $query ) {
// Get current meta Query
$meta_query = $query->get( 'meta_query' );
// Append our meta query
$meta_query = [
'key' => 'property_status',
'value' => 'sale',
'compare' => 'in',
];
$query->set( 'meta_query', $meta_query);
} );
This does not produce the results I wanted: it does not break my site, but I keep on getting a list of all of the properties. Just to test things, I also tried this code with other field types (text field & number field) and other comparison operators but with the same results. I also commented the lines above and entered the following line:
$query->set( 'post_type', 'agent' );
This does indeed give me a list of agents instead of properties, so at least I know the add_action is doing its work, which is worth something I suppose. Does anyone have any suggestions perhaps as to how I can adjust that meta query so that it actually works? I'm not a PHP developer, and not quite sure how to proceed from here. Any suggestions are greatly appreciated. I really would like to learn what I am doing wrong, as it would give me the opportunity to take my sites a little bit further.
'compare' => 'in'i think - Simone Rossaini