Last active
June 14, 2017 18:48
-
-
Save ChrisFlannagan/977285794cbc11c0e09c825b21a37cdd to your computer and use it in GitHub Desktop.
This file contains 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 | |
$flip_current = array_flip( $this->current_careers ); | |
foreach ( $careers_feed as $career ) { | |
/** | |
* check if post with post_name = $career['id'] exists | |
* | |
* If so, skip and remove from delete | |
*/ | |
$exists = $wpdb->get_var( $wpdb->prepare( | |
"SELECT ID FROM $wpdb->posts WHERE post_status = 'publish' AND post_name = %s AND post_type='career'", $career['id'] ) ); | |
if ( is_null( $exists ) ) { | |
$new_id = $this->create_career_post( $career ); | |
if ( $new_id ) { | |
$careers_new[] = $new_id; | |
} | |
} else { | |
/** | |
* If career with same id in database then remove it from the "current_careers" array so it won't get deleted | |
*/ | |
unset( $this->current_careers[ $flip_current[ $exists ] ] ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment