如何通过ACF嵌套字段abc.a=11构建WP REST API元查询?
Got it, let's break this down for you since you're working with ACF data via an API and only have access to the endpoint (no code changes allowed):
abc.a = 11 via API Query Parameters First, let's recall how ACF stores nested fields behind the scenes. When you have a field group like abc with sub-fields a and b, ACF doesn't store the entire abc object as a single database entry. Instead, each sub-field gets its own meta key in the format parent_field_subfield (using underscores to link the parent and child names).
Your example for filtering test=true uses a meta_query targeting the top-level test field. For the nested abc.a field, we just need to adjust the key to match ACF's stored meta key for that sub-field.
The Exact Query String
Here's the query you need to append to your API endpoint:
meta_query[0][key]=abc_a&meta_query[0][compare]==&meta_query[0][value]=11
If your API requires HTML-encoded ampersands (like your test example used & instead of &), use this version instead:
meta_query[0][key]=abc_a&meta_query[0][compare]==&meta_query[0][value]=11
Quick Notes:
- We use
compare=here becauseabc.ais an exact string value ("11")—this is more precise thanlike(which your test example used for a boolean value stored as1). If you ever need partial matches, you can swap back tocompare=like. - This works because ACF maps the nested
abc.afield to the meta keyabc_ain the WordPress database, so targeting that key directly will filter results whereabc.aequals "11".
内容的提问来源于stack exchange,提问作者NotABot

