• 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 1 year, 4 months ago by bluesix.
Viewing 3 replies - 1 through 3 (of 3 total)
  • 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:

    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 plugin to add the code snippet.

    You can handle create multiple placeholders in the code snippet. For example:

    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/

    • This reply was modified 1 year, 4 months ago by joneiseman.

    Correction, you can use php within event_list_item_format.php. You just need to surround it in <?php … ?> html tags liike this:

    <?php echo esc_html_e('More Info', 'events-manager'); ?>
    Thread Starter bluesix

    (@bluesix)

    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.