Skip to content

Instantly share code, notes, and snippets.

@mikeselander
Created July 2, 2016 11:54
Show Gist options
  • Save mikeselander/e5c24d18a8305960c867e7e455839e32 to your computer and use it in GitHub Desktop.
Save mikeselander/e5c24d18a8305960c867e7e455839e32 to your computer and use it in GitHub Desktop.
private function update_meta_ids( $pid ){
global $wpdb;
$img_id = get_post_meta( $pid, cmb_prefix( get_post_type( $pid ) ) . 'image_id', true);
$img = get_post_meta( $pid, cmb_prefix( get_post_type( $pid ) ) . 'image', true);
if ( empty( $img_id ) && ! empty( $img ) ){
$image = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE guid='%s';", $img ) );
if( ! empty( $image ) ) {
update_post_meta( $pid, cmb_prefix( get_post_type( $pid ) ) . 'image_id', $image[0] );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment