wp_insert_post() 位于 wp-includes/post.php /** * Insert a post. * * If the $postarr parameter has 'ID' set to a value, then post will be updated. * * You can set the post date manually, but setting the values for 'post_date' * and 'post_date_gmt' keys. You can close t...
'guid' => $wp_upload_dir['url'] . '/' . basename($image), 'post_title' => preg_replace('/\.[^.]+$/', '', basename($image)), 'post_mime_type' => $attachment_file_type['type'] ); $attachment_id = wp_insert_attachment($attachment_args, $image, $post_id); require_once...
wp_insert_post( array $postarr, bool $wp_error = false, bool $fire_after_hooks = true ) 函数参数 $postarr 数组 ID:文章的ID,如果传递0以外的值,则更新相应ID的文章而不是插入新的文章; post_author:作者的ID,默认为当前作者; post_date:发表时间,格式为Y-m-d H:i:s,默认为当前时间; post_...
WordPress自定义字段套件(WordPress Custom Fields Suite)是一个WordPress插件,它允许开发人员和网站管理员自定义和管理文章、页面和其他自定义内容类型的字段。 该套件提供了一个直观的用户界面,使用户能够轻松地创建和管理自定义字段。它支持各种字段类型,包括文本、数字、日期、下拉菜单、复选框等,以满足不同的需求。
Like other WordPress functions such asget_posts, thewp_insert_postfunction also has various parameters to facilitate custom post insertion. Here are some of the key parameters that you should be familiar with: ID– The ID of the post to update. If provided, the function will attempt to edit...
'post_status' => 'publish', 'post_author' => 1, 'post_category' =>array( 8,39 ) ); // 插入文章到数据库 wp_insert_post($my_post); 函数一般用在启用主题时创建一些默认页面,以及投稿中。 WordPress使用(40) 本文原创,作者:萨龙龙,其版权均为萨龙网络所有。
WordPress 5.6新增了一个动作挂钩wp_after_insert_post,以允许主题和插件开发人员在文章及其分类项和元数据已更新后运行自定义代码。 原有的save_post和相关动作钩子也可以用于此目的,但这些钩子会在经典编辑器之外的场景中(例如,在REST API、定制器中以及创建自动草稿时),在分类项和元数据被更新之前触发。
wp_insert_post(array('post_title'=>'文章标题','post_content'=>'文章内容','post_status'=>'pending'// 设置为待审核)) 其他参数详解: 'ID'(int) 文章ID。如果等于0以外的值,则将更新具有该ID的文章。默认值0。 'post_author'(int) 发布文章的用户的ID。默认值是当前用户ID。
一般来说,如果主题支持特色图像(缩略图),在主题的 functions.php 文件下加入以下代码就可以实现RSS ...
'post_content'=>'My new content!', 'post_status'=>'public', 'post_type'=>'my_post_type' ); $post_id=wp_insert_post($new_post); if($post_id){ // Update custom field on the new post update_post_meta($post_id,'my_custom_field','Hello!'); ...