【发布时间】:2020-07-06 04:53:19
【问题描述】:
我在 $_REQUEST 以及一个图像文件中获得了 post_title、post_content 和其他内容。我想将所有这些作为帖子保存在 wordpress 数据库中。我的页面上有
<?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);
?>
这会将数据库中的所有内容作为帖子获取,但我不知道如何添加附件及其帖子元数据。
我该怎么做?有谁能够帮我?我真的很困惑,花了几天时间试图解决这个问题。
【问题讨论】:
-
你应该包含 wp-load.php 而不是配置文件。