Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Runs on any post with post type "event" and updates the "Event" custom object with values Title and EventDate
- function create_update_event_object( $post_id, $post, $update ) {
- if ( $post->post_type != 'event' || ! function_exists( 'wp_fusion' ) ) {
- return;
- }
- add_filter( 'wpf_crm_object_type', function() {
- return 10011;
- } );
- $event_data = array(
- 'Title' => $post->post_title,
- 'EventDate' => get_post_meta( $post_id, 'event_date', true )
- );
- if ( $update == false ) {
- // New event
- $object_id = wp_fusion()->crm->add_contact( $event_data, false );
- if ( ! is_wp_error( $object_id ) ) {
- update_post_meta( $post_id, wp_fusion()->crm->slug . '_event_id', $object_id );
- }
- } else {
- // Existing event
- $object_id = get_post_meta( $post_id, wp_fusion()->crm->slug . '_event_id', true );
- wp_fusion()->crm->update_contact( $object_id, $event_data, false );
- }
- }
- add_action( 'wp_insert_post', 'create_update_event_object', 10, 3 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement