Skip to content

Instantly share code, notes, and snippets.

@lorenzocaum
Created August 14, 2016 16:45
Show Gist options
  • Save lorenzocaum/d4fa6981a2a93ed671b11bf0ba9e2a89 to your computer and use it in GitHub Desktop.
Save lorenzocaum/d4fa6981a2a93ed671b11bf0ba9e2a89 to your computer and use it in GitHub Desktop.
Edit the Events Table View Template add-on to show a field from Advanced Custom Fields

This can be done by relocating one of the templates and making a change to some lines of code. This will ensure that your customization is not lost on a software update.

Advanced Custom Fields has a get_field() function that can be used to retrieve and display information:

https://www.advancedcustomfields.com/resources/get_field/

For this tutorial, the name of the field will be instructor_name.

The support team at Event Espresso will never recommend you edit any core plugin or add-on files directly.

Here are the steps:

  1. Login to your WordPress root with your preferred SFTP or FTP client. Filezilla and Cyberduck are free options. On a Mac? Try Transmit

  2. Browse to this location:

/wp-content/plugins/eea-events-table-view-template/templates

You'll see two files there:

espresso-events-table-template-toggle.template.php

espresso-events-table-template.template.php

  1. Download a copy of the espresso-events-table-template.template.php file to your computer

  2. Now browse to this location:

/wp-content/uploads/espresso/templates

  1. Upload the the file that you downloaded earlier to the location above

  2. Open the espresso-events-table-template.template.php file for editing

At about line 45 you'll see this line of code:

	<th class="th-group"><?php _e('Venue','event_espresso'); ?></th>
  1. Replace the line above with this:
	<th class="th-group"><?php _e('Venue','event_espresso'); ?></th>
	<th class="th-group"><?php _e('Instructor Name','event_espresso'); ?></th>
  1. At about line 53, you'll see this line of code:
			<td colspan="4">
  1. Replace it with this since we are adding an additional column:
			<td colspan="5">
  1. At about line 111 you'll see this line of code:
		<td class="venue_title event-<?php echo $post->ID; ?>"><?php espresso_venue_name( NULL, FALSE ); ?></td>
  1. Replace the line above with this:
     <td class="venue_title event-<?php echo $post->ID; ?>"><?php espresso_venue_name( NULL, FALSE ); ?></td>
     <td class="acf_instructor_name event-<?php echo $post->ID; ?>"><?php echo get_field('instructor_name', $post->ID); ?></td>

Note that in the above change in step 11 we have introduced a CSS class should we want to adjust the styling. Then we are using get_field() from Advanced Custom Fields to display the information for the instructor_name field which we are using for this tutorial. You should use your actual field name in step 7 and step 11.

Then save changes.

Need to show additional information from other fields? Be sure to add a column name (see step 7), then increase the column count (see step 9), and finally add the new code for showing the field name (see step 11).

@lorenzocaum
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment