Support

Account

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.