WordPress插入附件信息到数据库函数:wp_insert_attachment
文 / @UTHEME
WordPress函数wp_insert_attachment用于插入一个附件信息到数据库。
wp_insert_attachment( string|array $args, string|false $file = false, int $parent, bool $wp_error = false, bool $fire_after_hooks = true )
函数参数
$args
数组
该参数可用的值可以参考wp_insert_post()函数,如果指定了ID,则更新现有附件信息。
$file
字符串
文件名
$parent
整数
父ID,例如要将该附件归属在哪篇文章下。
$wp_error
布尔值,默认值:false
发生错误时,是否返回WP_Error
$fire_after_hooks
布尔值,默认值:true
是否启用插入附件后的hooks
函数使用示例
wp_insert_attachment( array( 'guid' => $upload['url'], 'post_title' => sanitize_text_field( $title ), 'post_excerpt' => sanitize_text_field( $caption ), 'post_content' => sanitize_text_field( $description ), 'post_mime_type' => $response_headers['content-type'], ), $upload['file'], 0 );
扩展阅读
wp_insert_attachment()函数位于:wp-includes/post.php
相关函数:
- wp_parse_args()
- wp_insert_post()

相关文章
-
php 如何禁用notice错误报告(附:WordPress如何禁用notice错误报告) 2023-03-31 13:48:46
-
如何集成element-ui到wordpress后台 2023-03-31 10:04:13
-
WordPress本地化Avatars头像插件:Simple Local Avatars(附:WordPress代码实现本地化Avatars) 2023-03-30 11:23:57
-
sitemap的changefreq详解(附:跨境电商WordPress站的changefreq一般如何设置) 2023-03-27 17:59:27
-
详解sitemap.xml的priority(附:WordPress的priority设置意见) 2023-03-27 17:47:32
-
wordpress 刷新rewrite 规则 2023-03-24 15:07:29
-
如何在WordPress中进行URL重写(rewrite) 2023-03-24 14:57:14
-
如何用代码实现 JWT Authentication for WP REST API 的功能 2023-03-24 14:39:28
-
wordpress 如何实现纯静态缓存 2023-03-23 18:09:16
-
UTHEME工具箱 2023-03-23 10:40:12