Skip to content

Instantly share code, notes, and snippets.

@barryhughes
Created June 19, 2017 13:02
Show Gist options
  • Select an option

  • Save barryhughes/2e38cf6cd978255e87b5e74b6c6d4530 to your computer and use it in GitHub Desktop.

Select an option

Save barryhughes/2e38cf6cd978255e87b5e74b6c6d4530 to your computer and use it in GitHub Desktop.
Helper function: basic equivalent to update_post_meta() but targeting the ECP custom field implementation
<?php
/**
* Updates an Events Calendar PRO-style custom field.
*
* @param int $post_id
* @param string $field_label
* @param string $value
*/
function update_ecp_custom_field( $post_id, $field_label, $value ) {
$custom_fields = (array) tribe_get_option( 'custom-fields' );
$field_name = '';
foreach ( $custom_fields as $field_structure ) {
if ( $field_label === $field_structure['label'] ) {
$field_name = $field_structure['name'];
break;
}
}
if ( ! empty( $field_name ) ) {
update_post_meta( $post_id, $field_name, $value );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment