Created
June 19, 2017 13:02
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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