Home › Forums › General Issues › How to access ACF field in a custom WordPress Rest API endpoint? › Reply To: How to access ACF field in a custom WordPress Rest API endpoint?
No problem! So, I was just playing around with this, and if I grab the fields on the parent field, I get All Fields and Sub Fields of the FAQ page.
if (get_post_type() == 'page') {
array_push($results['pages'], array(
'title' => get_the_title(),
'link' => get_the_permalink(),
'faq' => get_field('faq-topic'),
));
}
Here’s an example of a response:
"faqs": [
{
"faq_group": {
"question": "What are your shop hours?",
"answer": "<p><strong>Our shop hours:</strong></p>\n<ul>\n<li>Monday – Thursday: 10-6 PM EST</li>\n<li>Friday: 10-5 PM EST</li>\n<li>Saturday: Closed</li>\n<li>Sunday: Closed</li>\n</ul>\n",
"linked_page": ""
}
}],
Where I’m really trying to go from here is to access both the question
and answer
and access them via javascript template literal, which I have working really well. All other post types and their respective fields are working nicely. I’m just struggling with this one.
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!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.