Support

Account

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

Solved

meta_query for a Group field sub-field

    • Nubee

    • January 23, 2018 at 6:47 am

    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 ?

    • LorneG

    • January 30, 2018 at 9:26 pm

    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!!

    • Nubee

    • February 2, 2018 at 3:00 am

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

    • Nubee

    • November 23, 2018 at 6:55 am

    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.

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

You must be logged in to reply to this topic.

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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.