Home › Forums › Add-ons › Repeater Field › Repeater Query Issue in WP 4.8.3
Any meta_query loops that are looking for repeater values do not return matches in WP 4.8.3. Ex: anything with repeater_name_%_repeater_field and using with a posts_where return. Likely due to this:
https://make.wordpress.org/core/2017/10/31/changed-behaviour-of-esc_sql-in-wordpress-4-8-3/
Any suggestions on a fix/workaround would be awesome.
You can follow comments on WP update post https://make.wordpress.org/core/2017/10/31/changed-behaviour-of-esc_sql-in-wordpress-4-8-3/#comment-33136 to find possible solutions. There are already few people that have issue with this new escaping.
Thanks kokers ! Your solution fix my problem :
function my_posts_where( $where ) {
global $wpdb;
$where = str_replace(
“meta_key = ‘locations_%”,
“meta_key LIKE ‘locations_%”,
$wpdb->remove_placeholder_escape($where)
);
return $where;
}
add_filter(‘posts_where’, ‘my_posts_where’);
Yep, tested this few times myself now, and it’s working ok.
So $wpdb->remove_placeholder_escape() to the rescue!
Hi, please could someone advise me on whether I can treat an ACF group in the same way as a repeater? I’m trying to query a subfield of the group field in this way but I’m having no luck. I’ve got my my_posts_where functions setup but something is wrong.
I’ve put my issue is on this forum thread..
https://support.advancedcustomfields.com/forums/topic/wp_query-with-meta_query-on-a-subfield-within-a-group-field/
Any help would be greatly appreciated.
I was having the same issue on a repeater field, not being able to patch it with @kokers ‘s solution.
This comment fixed it https://make.wordpress.org/core/2017/10/31/changed-behaviour-of-esc_sql-in-wordpress-4-8-3/#comment-33273. I don’t really get why but it might help someone !
Has anyone figured out how to do this dynamically for multiple keys and values. I tried something like this (below) but I can’t get it to work.
I have quite a few fields I need to be filtering for. I can get each field to work one at a time, but the second I try to do more than one, I see only field being filtered when i run “echo $GLOBALS[‘wp_query’]->request;”
Any help would be HUGE. I have been stuck on this for quite some time! Thank you in advance.
add_filter('posts_where', 'my_posts_where');
function my_posts_where( $where ) {
/* if( isset($_GET['feelings_$_feeling']) ) {
$where = str_replace("meta_key = 'feelings_$", "meta_key LIKE 'feelings_%", $where);
return $where;
} */
$rootkeys[] = $_GET;
global $wpdb; //TESTING
foreach($rootkeys as $rootkey) {
foreach($rootkey as $key => $value) {
$partialkey = explode("$",$key);
$keya = $partialkey[0];
$keyb = 'meta_key = \''.$keya.'$';
$keyc = 'meta_key LIKE \''.$keya.'%'; //this = was LIKE, should it be?
// $where = str_replace($keyb, $keyc, $where);
$where = str_replace($keyb, $keyc, $wpdb->remove_placeholder_escape($where));
}
}
return $where;
}
The topic ‘Repeater Query Issue in WP 4.8.3’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.