Home Forums General Issues Using ACF outside of a theme template


Using ACF outside of a theme template

  • Hi there,

    I have the following use case:

    I have created an Option Page that holds several discount coupons for an e-shop. I obviously don’t want these coupons to be printed anywhere in the theme.

    Every time a user inputs a coupon code, an AJAX function POSTs the code to check_coupon_handler.php. Inside this script, I would like to get all the Option Page coupons to check whether there is one that matches the user input.

    To achieve this, should I query directly the WP database, or is there a way to do so through the ACF API?

    Calling get_field from check_coupon_handler.php obviously results in an undefined function error. I tried requiring wp-blog-header.php as a start, but I’m not sure whether this path makes sense.


  • You should route all ajax calles through admin-ajax.php and use action hooks to run your checking.

  • Hi John,

    sorry for the late reply and thanks a lot for your kind heads up. I’ll look into that!



Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Using ACF outside of a theme template’ is closed to new replies.