WordPress
Custom fields
Daftarkan article_items dan faq_items di REST WordPress.
Lewati halaman ini jika koneksi memakai metode HTML.
WordPress mengabaikan meta yang belum di-register. Citora mengirim:
| Meta | Dipakai untuk |
|---|---|
article_items | Objek artikel (raw_body, image_ids) |
faq_items | Array { question, answer } |
Nama field baku. Jangan diganti.
Opsi 1 — plugin (disarankan)
Folder: wp-content/plugins/citora-integration/citora-integration.php
Aktifkan Citora Integration di Plugins.
Opsi 2 — functions.php tema
Cepat, hilang jika tema diganti.
Kode plugin
<?php
/**
* Plugin Name: Citora Integration
* Description: Mendaftarkan custom field untuk menerima data artikel dan FAQ dari Citora.
* Version: 1.1
*/
add_action('init', function () {
register_post_meta('post', 'article_items', [
'single' => true,
'type' => 'object',
'auth_callback' => function () {
return current_user_can('edit_posts');
},
'show_in_rest' => [
'schema' => [
'type' => 'object',
'properties' => [
'raw_body' => [
'type' => 'string',
],
'image_ids' => [
'type' => 'array',
'items' => [
'type' => 'integer',
],
],
],
],
],
]);
register_post_meta('post', 'faq_items', [
'single' => true,
'type' => 'array',
'auth_callback' => function () {
return current_user_can('edit_posts');
},
'show_in_rest' => [
'schema' => [
'type' => 'array',
'items' => [
'type' => 'object',
'properties' => [
'question' => [
'type' => 'string',
],
'answer' => [
'type' => 'string',
],
],
],
],
],
]);
});Jika konten ke custom post type, ganti 'post' di register_post_meta.
Verifikasi
Login wp-admin, buka:
https://namasitus.com/wp-json/wp/v2/posts?context=editObjek meta harus memuat article_items dan faq_items.