Home › Forums › Front-end Issues › 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!!
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',
,array(
'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?
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
🤔 Curious about the ACF user experience? So are we! Help guide the evolution of ACF by taking part in our first ever Annual Survey and guarantee you’re represented in the results. https://t.co/0cgr9ZFOJ5
— Advanced Custom Fields (@wp_acf) May 8, 2023
© 2023 Advanced Custom Fields.
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.