Skip to content

Instantly share code, notes, and snippets.

@ChrisFlannagan
Last active June 14, 2017 18:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChrisFlannagan/977285794cbc11c0e09c825b21a37cdd to your computer and use it in GitHub Desktop.
Save ChrisFlannagan/977285794cbc11c0e09c825b21a37cdd to your computer and use it in GitHub Desktop.
<?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