ProPeler
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
tmp
/
bsimport
/
Filename :
import_new30.php
back
Copy
<?php // Import 30 artikel baru + SEO. Run: wp eval-file import_new30.php if (!defined('WP_CLI')) { echo "Run via wp eval-file\n"; return; } $data = json_decode(file_get_contents('/tmp/bsimport/bs_new30.json'), true); if (!is_array($data)) { WP_CLI::error('bs_new30.json tidak sah'); } // tarikh lampau selamat: hari ini tolak (n..1) jam*3 $now = current_time('timestamp'); $i = 0; $created = 0; $skipped = 0; $n = count($data); foreach ($data as $a) { $slug = sanitize_title($a['slug']); $ex = get_posts(array('name'=>$slug,'post_type'=>'post','post_status'=>'any','numberposts'=>1,'fields'=>'ids')); if ($ex) { WP_CLI::log('skip (ada): '.$slug); $skipped++; $i++; continue; } $cat = get_category_by_slug($a['category']); $catid = $cat ? (int)$cat->term_id : 1; $ts = $now - (($n - $i) * 3 * 3600) - 3600; // semua pasti pada masa lampau $date = date('Y-m-d H:i:s', $ts); $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; } update_post_meta($pid,'bs_seo_title', $a['seo_title']); update_post_meta($pid,'bs_seo_desc', $a['meta_description']); update_post_meta($pid,'bs_focus_kw', $a['focus_keyword']); update_post_meta($pid,'bs_takeaway', $a['key_takeaway']); if (!empty($a['reviewed_note'])) update_post_meta($pid,'bs_reviewed_note', sanitize_text_field($a['reviewed_note'])); if (!empty($a['faq']) && is_array($a['faq'])) update_post_meta($pid,'bs_faq', wp_json_encode($a['faq'], JSON_UNESCAPED_UNICODE)); if (!empty($a['tags']) && is_array($a['tags'])) wp_set_post_terms($pid, $a['tags'], 'post_tag', false); WP_CLI::log("OK #$pid $slug"); $created++; $i++; } WP_CLI::success("Artikel dicipta: $created, dilangkau: $skipped");