Skip to content

Instantly share code, notes, and snippets.

@labboy0276
Created May 19, 2020 14:13
Show Gist options
  • Save labboy0276/672e98121aff6a1ae7fcf5a5a18d2e27 to your computer and use it in GitHub Desktop.
Save labboy0276/672e98121aff6a1ae7fcf5a5a18d2e27 to your computer and use it in GitHub Desktop.
GF Advanced Post Creation Add On Non Duplication Patch
diff --git a/class-gf-advancedpostcreation.php b/class-gf-advancedpostcreation.php
index 1c58a64..b5ae638 100644
--- a/class-gf-advancedpostcreation.php
+++ b/class-gf-advancedpostcreation.php
@@ -1793,14 +1793,19 @@ class GF_Advanced_Post_Creation extends GFFeedAddOn {
// Initialize uploaded files array.
$this->set_current_media();
- // Prepare post object.
- $post = array(
- 'post_status' => $feed['meta']['postStatus'],
- 'post_type' => $feed['meta']['postType'],
- 'post_title' => $this->get_post_title( $feed, $entry, $form ),
- 'comment_status' => rgars( $feed, 'meta/postComments' ) ? 'open' : 'closed',
- 'ping_status' => rgars( $feed, 'meta/postPingbacks' ) ? 'open' : 'closed',
- );
+ // Additions to allow non duplication of posts.
+ $title = $this->get_post_title( $feed, $entry, $form );
+ $existing_post = get_page_by_title( $title, OBJECT, $feed['meta']['postType'] );
+
+ // Prepare post object.
+ $post = array(
+ 'ID' => $existing_post !== NULL ? $existing_post->ID : NULL,
+ 'post_status' => $feed['meta']['postStatus'],
+ 'post_type' => $feed['meta']['postType'],
+ 'post_title' => $title,
+ 'comment_status' => rgars( $feed, 'meta/postComments' ) ? 'open' : 'closed',
+ 'ping_status' => rgars( $feed, 'meta/postPingbacks' ) ? 'open' : 'closed',
+ );
// Create base post object.
$post_id = wp_insert_post( $post, true );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment