hello in my project I have a coupon list (repeater) for each registered user, the coupon comes with expiry date and coupon amount that can be used.
I came across this tutorial under “4. Sub custom field values” that I can search for repeater fields with WP_query using the meta_key but it doesn’t seem to be working with WP_user_query. Does anyone have experience with it?
https://www.advancedcustomfields.com/resources/query-posts-custom-fields/
thanks,
Felix
updated, found the solution!
there is a similar “post_where” filter for WP_User_Query, that you can filter out the repeater sub field values.
function user_meta_callback( $user_query )
{
global $wpdb;
$user_query->query_where = str_replace("meta_key = 'coupons_$", "meta_key LIKE 'coupons_%", $user_query->query_where);
}
add_filter('pre_user_query', 'user_meta_callback');
$q = new WP_User_Query(array(
'numberposts' => -1,
'meta_query' =>
array(
'relation' => 'OR',
array(
'key' => 'coupons_$_date',
'compare' => '>=',
'value' => '2018-11-01',
'type' => 'DATE'
)
)
));