您的当前位置:首页 > 知识博客 > wordpress建站

WordPress根据附件ID获取文件路径函数:get_attached_file

时间:2024-03-09

WordPress函数get_attached_file根据附件的ID返回对应附件的完整路径。

get_attached_file( int $attachment_id, bool $unfiltered = false )

函数参数

$attachment_id

整数

附件ID

$unfiltered

布尔值,默认值:false

是否应用过滤器。

函数返回值

/home/tiezhushuo/htdocs/wordpress/wp-content/uploads/2020/10/theme-tiezhushuo.webp

函数使用示例

$attachment_id = 3645;
$path = get_attached_file($attachment_id);
$filename = basename($path);

扩展阅读

get_attached_file()函数位于:wp-includes/post.php

相关函数:

  • wp_get_upload_dir()

  • get_post_meta()

  • wp_attachment_is()


欢迎咨询/Welcome to inquire
tel/vx:18842938855
qq:1685522781
email:1685522781@qq.com

Copyright © 2019-2024 java.fit


Whatsapp
Powered by RRZCMS