check if tag exists in wp database

I think you’re looking for term_exists function.

Example Code:

<?php
$term = term_exists('tag1', 'post_tag');
if ($term !== 0 && $term !== null) {
  echo "'tag1' post_tag exists!";
} else {
    echo "'tag1' post_tag does not exist!";
}
?>

Leave a Comment