500 kadar alt kategorilerle beraber Woocommerce kategorisi bulunuyor. Bunları Wordpress sayfası olarak değiştirmek istiyoruz ve alt sayfa yapısı bozulmadan. Bunun için bir eklenti mevcut mudur?
Teşekkür ederim.
ÇÖZÜM:
Aşağıda yer alan kodu functions.php dosyası en sonuna ekledim ve kaydettim. 1 saniye içinde hepsi oldu. Sonra da kodu sildim.
add_action('admin_init', 'convert_product_categories_to_pages_with_hierarchy');
function convert_product_categories_to_pages_with_hierarchy() {
if (get_option('product_categories_converted_with_hierarchy')) {
return;
}
$args = array(
'taxonomy' => 'product_cat',
'hide_empty' => false,
);
$categories = get_terms($args);
// Kategori ID'lerine göre oluşturulan sayfa ID'lerini tutmak için bir eşleme
$category_page_map = array();
// Önce tüm kategoriler oluşturulmalı, ardından hiyerarşi kurmalı
foreach ($categories as $category) {
// Sayfa zaten var mı kontrolü
$existing_page = get_page_by_title($category->name);
if ($existing_page) {
$page_id = $existing_page->ID;
} else {
// Üst kategorinin sayfa ID'si varsa post_parent olarak al
$parent_id = 0;
if ($category->parent && isset($category_page_map[$category->parent])) {
$parent_id = $category_page_map[$category->parent];
}
// Sayfa oluştur
$page_id = wp_insert_post(array(
'post_title' => $category->name,
'post_content' => $category->description,
'post_status' => 'publish',
'post_type' => 'page',
'post_name' => $category->slug,
'post_parent' => $parent_id,
));
}
// Eşleme kaydet
$category_page_map[$category->term_id] = $page_id;
}
update_option('product_categories_converted_with_hierarchy', 1);
}