Sto ricevendo post_title, post_content e altre cose in $ _REQUEST, nonché un file immagine. Voglio salvare tutto ciò come un post nel database di wordpress. Ho sulla mia paginaAggiunta di Wordpress a livello di codice con allegato
<?php
require_once("wp-config.php");
$user_ID; //getting it from my function
$post_title = $_REQUEST['post_title'];
$post_content = $_REQUEST['post_content'];
$post_cat_id = $_REQUEST['post_cat_id']; //category ID of the post
$filename = $_FILES['image']['name'];
//I got this all in a array
$postarr = array(
'post_status' => 'publish',
'post_type' => 'post',
'post_title' => $post_title,
'post_content' => $post_content,
'post_author' => $user_ID,
'post_category' => array($category)
);
$post_id = wp_insert_post($postarr);
?>
In questo modo ottenere tutte le cose in database come post, ma non so come aggiungere l'attaccamento e la sua posta meta.
Come posso farlo? Qualcuno può aiutarmi? Sono davvero confuso e ho passato qualche giorno a cercare di risolvere questo problema.
Si dovrebbe essere compresi il wp-load.php invece di file di configurazione. –