Title: Using ACF / PHP in templates
Last modified: July 4, 2023

---

# Using ACF / PHP in templates

 *  Resolved [bluesix](https://wordpress.org/support/users/bluesix/)
 * (@bluesix)
 * [2 years, 11 months ago](https://wordpress.org/support/topic/using-php-in-templates/)
 * I’ve setup some custom fields in our events using ACF.
 * I’m editing event_list_item_format.php template (in a child theme), but don’t
   seem to be able to call the ACF functions. How can I use PHP in the EM templates?
   get_field() doesn’t appear to be working.
    -  This topic was modified 2 years, 11 months ago by [bluesix](https://wordpress.org/support/users/bluesix/).

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

 *  [joneiseman](https://wordpress.org/support/users/joneiseman/)
 * (@joneiseman)
 * [2 years, 11 months ago](https://wordpress.org/support/topic/using-php-in-templates/#post-16868465)
 * You can’t directly use PHP in the templates. However, interestingly, you can 
   create your own placeholders. Let’s say you want to create a placeholder called#
   _EVENTURL and the value was stored as an ACF called ‘eventurl’. Then you would
   add the following code snippet to create the #_EVENTURL placeholder:
 *     ```wp-block-code
       add_filter('em_event_output_placeholder','my_em_output_placeholders',1,3);
       function my_em_output_placeholders($replace, $EM_Event, $result){
           if( preg_match( '/#_EVENTURL.*/', $result ) ) {
               $url = get_field('eventurl', $EM_Event->post_id);
               if ( empty( $url ) ) {
                   $replace = $url;
               }
           }
           return $replace;
       }
       ```
   
 * You could then add #_EVENTURL to the template.
 * You could use the [Code Snippets](https://wordpress.org/plugins/code-snippets/)
   plugin to add the code snippet.
 * You can handle create multiple placeholders in the code snippet. For example:
 *     ```wp-block-code
       add_filter('em_event_output_placeholder','my_em_output_placeholders',1,3);
       function my_em_output_placeholders($replace, $EM_Event, $result){
           if( preg_match( '/#_FIELD1.*/', $result ) ) {
               $url = get_field('field1', $EM_Event->post_id);
               if ( empty( $url ) ) {
                   $replace = $url;
               }
           }
           else if( preg_match( '/#_FIELD2.*/', $result ) ) {
               $url = get_field('field2', $EM_Event->post_id);
               if ( empty( $url ) ) {
                   $replace = $url;
               }
           }
           return $replace;
       }
       ```
   
 * Here’s the documentation on the em_event_output_placeholder filter: [https://wp-events-plugin.com/tutorials/create-a-custom-placeholder-for-event-formatting/](https://wp-events-plugin.com/tutorials/create-a-custom-placeholder-for-event-formatting/)
    -  This reply was modified 2 years, 11 months ago by [joneiseman](https://wordpress.org/support/users/joneiseman/).
 *  [joneiseman](https://wordpress.org/support/users/joneiseman/)
 * (@joneiseman)
 * [2 years, 11 months ago](https://wordpress.org/support/topic/using-php-in-templates/#post-16868818)
 * Correction, you can use php within event_list_item_format.php. You just need 
   to surround it in <?php … ?> html tags liike this:
 *     ```wp-block-code
       <?php echo esc_html_e('More Info', 'events-manager'); ?>
       ```
   
 *  Thread Starter [bluesix](https://wordpress.org/support/users/bluesix/)
 * (@bluesix)
 * [2 years, 11 months ago](https://wordpress.org/support/topic/using-php-in-templates/#post-16870153)
 * Perfect, thank you! Using `em_event_output_placeholder` did exactly what I wanted.
   Thanks!

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

The topic ‘Using ACF / PHP in templates’ is closed to new replies.

 * ![](https://ps.w.org/events-manager/assets/icon-256x256.png?rev=3550347)
 * [Events Manager - Calendar, Bookings, Tickets, and more!](https://wordpress.org/plugins/events-manager/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/events-manager/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/events-manager/)
 * [Active Topics](https://wordpress.org/support/plugin/events-manager/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/events-manager/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/events-manager/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [bluesix](https://wordpress.org/support/users/bluesix/)
 * Last activity: [2 years, 11 months ago](https://wordpress.org/support/topic/using-php-in-templates/#post-16870153)
 * Status: resolved