如何在以编程方式创建帖子时向帖子中添加自定义字段?
我试图以编程方式创建一个post,并将一个值存储在直接从PhpMyAdmin创建的列中。
以下是我创建帖子的方式:
$post_title = $post->title->rendered;
$post_content = $post->content->rendered;
$post_check = get_page_by_title($post_title);
$post = array(
\'post_type\' => \'post\',
\'post_title\' => $post_title,
\'post_content\' => $post_content,
\'post_status\' => \'publish\',
\'post_author\' => 1,
\'post_slug\' => $post_title,
\'post_imported_id\' => 3
);
$post_id = wp_insert_post($post);
if ($post_id) {
add_post_meta( $post_id, \'post_imported_id\', 3 );
}
帖子已创建,所有默认字段也已妥善保存。
问题是没有考虑我的“post\\u imported\\u id”。