Created
September 25, 2018 14:25
-
-
Save tallesairan/31293b3b433217dcfa1e7966fea71f8d to your computer and use it in GitHub Desktop.
Query posts by ACF Repeater field, change repeaterName for your repeater name
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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