hocam konuyu hortlatmış gibi olucam ama kategoriyide çekmesi için bir kod daha ekleme imkanınız varmı eski site içeriklerimi yeni siteme yüklüyorum şuanda yardımcı olursanız sevinirim
@B4RIS;
@shms;
<?php
/*
Plugin Name: Category, Post, and Page Importer
Description: Belirtilen WordPress sitesinden kategoriler, yazılar ve sayfaları REST API ile çekip yeni siteye ekler.
Version: 1.1
Author: Your Name
*/
// REST API aracılığıyla içerik çekme fonksiyonu
function import_content_from_source_site($source_site_url) {
if (empty($source_site_url)) {
return; // URL boşsa işlem yapılmaz
}
// Kategorileri kaynaktan çek
$categories = json_decode(file_get_contents($source_site_url . '/categories'));
if (is_array($categories)) {
// Çekilen kategorileri hedef siteye ekle
foreach ($categories as $category) {
$term = wp_insert_term($category->name, 'category', array(
'description' => $category->description,
'slug' => $category->slug
));
// Eğer kategori başarıyla eklendiyse yazıları çek
if (!is_wp_error($term)) {
$category_id = $category->id;
// Kategoriye ait yazıları kaynaktan çek
$posts = json_decode(file_get_contents($source_site_url . '/posts?categories=' . $category_id));
if (is_array($posts)) {
foreach ($posts as $post) {
// Yazıyı hedef siteye ekle
wp_insert_post(array(
'post_title' => $post->title->rendered,
'post_content' => $post->content->rendered,
'post_status' => 'publish',
'post_author' => 1,
'post_category'=> array($term['term_id']),
));
}
}
}
}
}
// Sayfaları kaynaktan çek
$pages = json_decode(file_get_contents($source_site_url . '/pages'));
if (is_array($pages)) {
foreach ($pages as $page) {
wp_insert_post(array(
'post_title' => $page->title->rendered,
'post_content' => $page->content->rendered,
'post_status' => 'publish',
'post_type' => 'page',
'post_author' => 1
));
}
}
}
// Yönetim panelinde eklentiyi çalıştırmak için bir menü ekleyin
function category_post_importer_menu() {
add_menu_page(
'İçerik İçe Aktar',
'İçerik İçe Aktar',
'manage_options',
'category-post-importer',
'category_post_importer_admin_page'
);
}
add_action('admin_menu', 'category_post_importer_menu');
// Yönetim sayfası içeriği
function category_post_importer_admin_page() {
echo '<h1>İçerik İçe Aktar</h1>';
echo '<form method="post" action="">';
echo '<label for="source_site_url">Kaynak Site URL\'si:</label>';
echo '<input type="text" id="source_site_url" name="source_site_url" value="' . (isset($_POST['source_site_url']) ? esc_attr($_POST['source_site_url']) : '') . '" size="50">';
echo '<br><br>';
echo '<input type="submit" name="import_content" value="Çek" class="button button-primary">';
echo '</form>';
// Eğer form gönderildiyse içerik çekme fonksiyonunu çağır
if (isset($_POST['import_content']) && !empty($_POST['source_site_url'])) {
$source_site_url = esc_url_raw($_POST['source_site_url']) . '/wp-json/wp/v2';
// İçeriği çek
import_content_from_source_site($source_site_url);
echo '<div class="updated"><p>İçerikler başarıyla içe aktarıldı.</p></div>';
}
}
?>