以下內容属于 ‘附件信息’ 便签:

WordPress获取附件的名字和大小

WordPress获取附件信息,比如附件的名字和大小。在网上找了一圈,不太适合我要用的场景,后面在stackoverflow上面找到了合胃口的。记录一下,也分享给你。 12345678910111213141516// retrieve file of the custom field  $file = get_post_meta(get_the_ID(), 'wp_custom_attachment', true);  //get the url  $url = $file['url'];  //Replace url to directory path   $path = str_replace( site_url('/'), ABSPATH, esc_url( $url) );   if ( is_file( $path ) ){     $filesize = size_format( filesize( $path ) );     $filename = basename($path);   […] (more...)