Suppose you have a repeater field labeled My Repeater Field , and this repeater contains at least one field labeled Field A on the repeater .
Assuming you have the default wp_ table prefix, you need to look at the wp_postmeta DB table to notice that the values ββfor this field in the relay are stored using meta_key :
NAME_OF_THE_REPEATER_index_NAME_OF_FIELD_ON_THE_REPEATER
So, in our case, if the message has 3 lines in the repeater field, its values ββwill be saved as:
my_repeater_field_0_a_field_on_the_repeater my_repeater_field_1_a_field_on_the_repeater my_repeater_field_2_a_field_on_the_repeater
Knowing this, if you want to request all messages that have at least one line on the repeater, you can do:
$meta_query = [ [ 'key' => 'my_repeater_field_0_a_field_on_the_repeater', 'compare' => 'EXISTS', ] ]; $args = [ 'posts_per_page' => -1, 'orderby' => 'date', 'order' => 'DESC', 'meta_query' => $meta_query, 'post_type' => 'post', 'post_status' => 'publish', ]; $posts_array = get_posts( $args );
Note. As stated in WP Docs , you can use the EXISTS comparison for WP> = 3.5, and you do not need to specify a value when using the "EXISTS" or "NOT EXISTS" comparisons in WordPress 3.9 and later. I also assume that you are using PHP> = 5.4 to use the syntax of short arrays. If not, just replace [] with array() .
source share