post_exists fonksiyonunu da kullanabilirsiniz;
$translation_text = trim($translation->translated_text);
// Split translation text into words
$words = explode(' ', $translation_text);
// Get the first 5 words or less for the title
$title_words = array_slice($words, 0, 5);
$post_title = implode(' ', $title_words);
// Limit title to maximum 45 characters
$post_title = mb_substr($post_title, 0, 45);
if (post_exists($post_title)){
return false;
}
$tags = array();
// Calculate the remaining characters for tags
$remaining_chars = 50;
// Determine the tag words based on the remaining characters and word count
foreach ($words as $word) {
if ($remaining_chars >= mb_strlen($word)) {
$tags[] = sanitize_title($word);
$remaining_chars -= mb_strlen($word) + 1; // Include space character
} else {
break;
}
}