Home Forums Front-end Issues meta_query for a Group field sub-field


meta_query for a Group field sub-field

  • Hi! I’m having an issue with meta_query.

    Here is what my meta_query looks like, as overwritten in pre_get_posts :

    $metaQuery = [
    	'relation'		=> 'AND',
    		'key'			=> 'stamps_%_local',
    		'compare'		=> '=',
    		'value'			=> true,

    Where “stamps” is a Group field, and “local” is a True/False sub-field of it. I tried following the same method as with repeaters, but it doesn’t seem to be working. It returns no results. Is it possible to do a meta_query on such sub-fields ?

  • Hey Nubee..

    So close! But its actually just a bit simpler.. your meta ‘key’ only needs to be the name of the group, then underscore, then the name of the sub-field… so in your case:

    $metaQuery = [
    	'relation'		=> 'AND',
    		'key'			=> 'stamps_local',
    		'compare'		=> '=',
    		'value'			=> true,

    Hope this helps!!

  • Thank you very much for your help. It works just fine now.

  • Back with an other question haha.

    What do I do if my group field’s slug has an underscore in it ?

    I mean, I could just change it to make it “my-group-field” instead of “my_group_field”, but it is in your system that when I write a field’s name with spaces, it replaces them with underscores, so that’s a shame.

  • This doesn’t work. As of WP 5.9.3 and the latest ACF on Apr 10, 2022, this code doesn’t work:

    // WP_Query args fragment..
    'post_type'  => 'page'
    ,'meta_query' => array(
            'relation' => 'OR',
                'key' => 'page_sections_section_content',
                'value' => "$SEARCH",
                'compare' => 'LIKE',

    My repeater rows: page_sections
    My repeater rows: section_content

    Any ideas?

  • @pkhunter The key looks fine. Did you try tweaking the value or compare? Or even just running only that key without the OR?

Viewing 6 posts - 1 through 6 (of 6 total)

The topic ‘meta_query for a Group field sub-field’ is closed to new replies.