AdvancedCustomFields / AdvancedCustomFields/acf
ACF fields not included in REST response during "multiple content type" search
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 945
- Forks
- 197
- PR merge metrics
- No merged PRs in 30d
Description
When doing a REST search against multiple content types (with e.g. https://github.com/elevati/wp-api-multiple-posttype), ACF Pro doesn't inject acf field into the search results.
This is because ACF only injects data to a REST response when it sees that the request is coming for a certain known post type: https://github.com/AdvancedCustomFields/acf/blob/ada1e58a2e5564e7d62ded661ebdaf6a153ccb1f/includes/rest-api/class-acf-rest-api.php#L60-L64
Any way to overcome that programmatically? Such as when processing said search request somehow explicitly provide the list of object sub types for which ACF should inject the fields? I would possibly call register_rest_field myself it but I'm not sure how to discover the global ACF_Rest_Api instance.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading includes/rest-api/class-acf-rest-api.php around lines 60-64 and trace how the ACF_Rest_Api instance handles REST responses for known post types. Reproduce a multiple-content-type search using the linked wp-api-multiple-posttype example, then verify that search results for every requested type include the acf field without requiring an undiscovered global instance.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100