Skip to content

Commit

Permalink
Always cast term_ids as integers.
Browse files Browse the repository at this point in the history
Passing term IDs to WP as strings results in WP
making new terms. For existing terms, always cast
the ID as an integer to avoid this issue (and to
ensure a match).
  • Loading branch information
dcavins committed Jun 26, 2017
1 parent c2e2913 commit a577e6a
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions class-wxr-importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2319,18 +2319,18 @@ protected function term_exists( $data ) {

// Constant-time lookup if we prefilled
if ( $this->options['prefill_existing_terms'] ) {
return isset( $this->exists['term'][ $exists_key ] ) ? $this->exists['term'][ $exists_key ] : false;
return isset( $this->exists['term'][ $exists_key ] ) ? (int) $this->exists['term'][ $exists_key ] : false;
}

// No prefilling, but might have already handled it
if ( isset( $this->exists['term'][ $exists_key ] ) ) {
return $this->exists['term'][ $exists_key ];
return (int) $this->exists['term'][ $exists_key ];
}

// Still nothing, try WP's term_exists, and cache it.
$exists = term_exists( $data['slug'], $data['taxonomy'] );
if ( is_array( $exists ) ) {
$exists = $exists['term_id'];
$exists = (int) $exists['term_id'];
}

$this->exists['term'][ $exists_key ] = $exists;
Expand Down

0 comments on commit a577e6a

Please sign in to comment.