my_query_filters not showing filter results in the archive.php with repeater sub_fields. I am getting the value but when trying to filter the post it does not show any result. rest normal fields showing result fine. here is the code i am using in my functions.php:
// array of filters (field key => field name)
$GLOBALS[‘my_query_filters’] = array(
‘field_5ebae4d1733b7’ => ‘starting_price’,
‘field_5eb8f98a60609’ => ‘coupon_start_date’, //Repeater sub_field
‘field_5eb8fdc433e09’ => ‘coupon_end_date’, //Repeater sub_field
‘field_5eb8fa4deffb6’ => ‘private_coupon’, //Repeater sub_field
‘field_5eb8fd31628b2’ => ‘refundable’,
‘field_5eb6b8a81305c’ => ‘star_rating’
);
// action
add_action(‘pre_get_posts’, ‘my_pre_get_posts’, 10, 1);
function my_pre_get_posts( $query ) {
// bail early if is in admin
if( is_admin() ) return;
// bail early if not main query
// – allows custom code / plugins to continue working
if( !$query->is_main_query() ) return;
// get meta query
$meta_query = $query->get(‘meta_query’);
// loop over filters
foreach( $GLOBALS[‘my_query_filters’] as $key => $name ) {
// continue if not found in url
if( empty($_GET[ $name ]) ) {
continue;
}
// get the value for this filter
// eg: http://www.website.com/events?city=melbourne,sydney
$value = explode(‘,’, $_GET[ $name ]);
// append meta query
$meta_query[] = array(
‘key’ => $name,
‘value’ => $value,
‘compare’ => ‘LIKE’,
);
}
// update meta query
$query->set(‘meta_query’, $meta_query);
}