Last active
September 22, 2021 16:11
-
-
Save jonathanstegall/afef1e44e27ab817eed7d9f5ab674d83 to your computer and use it in GitHub Desktop.
possible answer to https://wordpress.org/support/topic/wp-to-sf-object-record-id/
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 | |
| add_action( 'object_sync_for_salesforce_push_success', 'save_sf_id_acf', 10, 5 ); | |
| function save_sf_id_acf( $op, $response, $synced_object, $object_id, $wordpress_id_field_name ) { | |
| // do things if the save succeeded | |
| // $op is what the plugin did - Create, Update, Upsert, Delete | |
| // $response is what was returned by the $salesforce class. sfapi->response | |
| // $synced_object is an array like this: | |
| /* | |
| $synced_object = array( | |
| 'wordpress_object' => $object, | |
| 'mapping_object' => $mapping_object, | |
| 'queue_item' => false, | |
| 'mapping' => $mapping, | |
| ); | |
| */ | |
| // you might want to exit out if it's not a newly created record, like this: | |
| if ( 'Create' !== $op ) { | |
| return; | |
| } | |
| // $object_id is the salesforce object id | |
| // $wordpress_id_field_name is the name of the ID field in WordPress | |
| // so the WP post ID would be stored in $synced_object['wordpress_object'][ $wordpress_id_field_name ] | |
| $post_id = $synced_object['wordpress_object'][ $wordpress_id_field_name ]; | |
| // you would need to figure out what $field_name should be using somehow | |
| update_field( $field_name, $object_id, $post_id ); // this is an ACF method | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment