ProPeler
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
tmp
/
bsimport
/
Filename :
import_articles.php
back
Copy
<?php // Import artikel Bayi Sihat dari manifest JSON. Jalankan: wp eval-file import_articles.php if (!defined('WP_CLI')) { echo "Run via wp eval-file\n"; return; } $path = '/tmp/bsimport/bs_manifest.json'; $man = json_decode(file_get_contents($path), true); if (!is_array($man)) { WP_CLI::error('Manifest tidak sah: ' . $path); } $base = strtotime('2026-06-08 09:30:00'); $i = 0; $created = 0; $skipped = 0; foreach ($man as $a) { $slug = sanitize_title($a['slug']); $existing = get_posts(array('name'=>$slug,'post_type'=>'post','post_status'=>'any','numberposts'=>1,'fields'=>'ids')); if (!empty($existing)) { WP_CLI::log("skip (sudah ada): $slug"); $skipped++; $i++; continue; } $cat = get_category_by_slug($a['category']); $catid = $cat ? intval($cat->term_id) : 1; $date = date('Y-m-d H:i:s', $base + ($i * 2 * 86400)); $pid = wp_insert_post(array( 'post_title' => wp_strip_all_tags($a['title']), 'post_name' => $slug, 'post_content' => $a['content'], 'post_excerpt' => sanitize_text_field($a['excerpt']), 'post_status' => 'publish', 'post_type' => 'post', 'post_author' => 1, 'post_date' => $date, 'post_date_gmt'=> get_gmt_from_date($date), 'post_category'=> array($catid), ), true); if (is_wp_error($pid)) { WP_CLI::warning($slug . ': ' . $pid->get_error_message()); $i++; continue; } if (!empty($a['reviewed_note'])) update_post_meta($pid, 'bs_reviewed_note', sanitize_text_field($a['reviewed_note'])); if (!empty($a['tags']) && is_array($a['tags'])) wp_set_post_terms($pid, $a['tags'], 'post_tag', false); WP_CLI::log("OK #$pid: " . $a['title']); $created++; $i++; } WP_CLI::success("Artikel dicipta: $created, dilangkau: $skipped");