I try to add a filter to make an elementor post widget displays the posts depending on a certain custom field.
The custom field key is adress
and contains an array with some keys like street_number, street_name, city, post_code etc.
add_action( 'elementor/query/filterByPostCode', function( $query ) {
if ('field' === $_GET['getby']) {
$meta_query = $query->get('meta_query');
if (!$meta_query) {
$meta_query = [];
}
$meta_query[] = [
'key' => 'adress',
'value' => [
'key' => 'post_code',
'value' => $_GET['field'],
'compare' => '='
],
];
$query->set('meta_query', $meta_query);
}
});
What will be the correct query ?
Thanks for help