<?php
// Ensure WordPress environment is loaded if this code is run outside a plugin or theme file.
// For example, if running as a standalone script, you might need:
// require_once( $_SERVER['DOCUMENT_ROOT'] . '/wp-load.php' );


$category_name = 'Cledaners';
$category_id = 0; // Initialize with 0

// Check if the category already exists
$existing_category = get_term_by('name', $category_name, 'category');
echo "soso"; exit;
if ($existing_category) {
    // Category exists, get its ID
    $category_id = $existing_category->term_id;
    echo "Category '{$category_name}' already exists with ID: {$category_id}\n";
} else {
    // Category does not exist, create it
    $new_category = wp_insert_term(
        $category_name, // The term name
        'category',      // The taxonomy
        array(
            'slug' => sanitize_title($category_name) // Generate a slug from the name
        )
    );

    if (!is_wp_error($new_category)) {
        // Category created successfully, get its ID
        $category_id = $new_category['term_id'];
        echo "Category '{$category_name}' created with ID: {$category_id}\n";
    } else {
        // Error creating the category
        echo "Error creating category '{$category_name}': " . $new_category->get_error_message() . "\n";
    }
}

// $category_id now holds the ID of the 'Cleaners' category, whether it was existing or newly created.
// You can use this $category_id for further operations, e.g., assigning posts to it.
//? >