Skip to content

Instantly share code, notes, and snippets.

@tallesairan
Created September 25, 2018 14:25
Show Gist options
  • Save tallesairan/31293b3b433217dcfa1e7966fea71f8d to your computer and use it in GitHub Desktop.
Save tallesairan/31293b3b433217dcfa1e7966fea71f8d to your computer and use it in GitHub Desktop.
Query posts by ACF Repeater field, change repeaterName for your repeater name
/**
* Allow hooking into ACF repeated fields with meta queries
*/
function repeaterAdapter( $where ) {
$where = str_replace("meta_key = 'repeaterName_$", "meta_key LIKE 'repeaterName_%", $where);
return $where;
}
add_filter('posts_where', 'repeaterAdapter');
$os = new WP_Query( [
'post_type' => 'os',
'post_status' => 'publish',
'posts_per_page' => 5,
'paged' => $paged,
'meta_query' => array(
'relation' => 'LIKE',
array(
'key' => 'repeaterName_$_field',
'compare' => '=',
'value' => 22,
)),
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment