您不需要使用post_meta
这里,因为所有信息都可以在posts
.
要插入新帖子,请使用wp_insert_post( $post )
, 并将参数传递给$post
-大堆此函数可以返回WP_Error
-对象进行错误处理(如果第二个参数设置为true
, 错误时返回0(如果为false),并返回ID
插入立柱的。
请参阅的完整参数列表wp_insert_post()
在Codex.
$post = array(
\'post_content\' => $content, // The content you want to have set in the content
\'post_title\' => $title, // The title of your post.
\'post_status\' => \'publish\', // Whatever status you want to have
\'post_type\' => \'your_custom_post_type\' // the slug of your custom post type
);
$thisid = wp_insert_post( $post, true ); // insert the post and allow WP_Error object
if ( is_wp_error( $thisid ) ) {
// Error handling
} else {
// the rest of your code, inserting metadata
update_post_meta( $thisid, \'your_meta_key\', $your_meta_value );
}