Php WordPress特色图片的实际文件位置?

Php WordPress特色图片的实际文件位置?,php,wordpress,Php,Wordpress,我正在为“垃圾”中的某些帖子生成查询。我可以检索特色图像URL,但我正在寻找一种方法来获取服务器上的特色图像文件位置 # generate the query foreach ( $query as $post ) { $thumbID = get_post_thumbnail_id( $post->ID ); $thumbObj = get_post( $thumbID ); $source_url = $thumbObj->guid; # how

我正在为“垃圾”中的某些帖子生成查询。我可以检索特色图像URL,但我正在寻找一种方法来获取服务器上的特色图像文件位置

# generate the query
foreach ( $query as $post ) {
    $thumbID = get_post_thumbnail_id( $post->ID );
    $thumbObj = get_post( $thumbID );
    $source_url = $thumbObj->guid;
    # how do I get the string "/path/to/wordpress/media/library/thumbnail.jpg" ?
}

我找不到任何返回实际特色图像文件位置的WordPress函数。

没有wp函数,但很容易创建自己的功能,例如

function return_image_path($thumbID) {

    $image= wp_get_attachment_image_src($thumbID);
    $imagepath= str_replace(get_site_url(), $_SERVER['DOCUMENT_ROOT'], $image[0]);

    if($imagepath) return $imagepath;

    return false;

}

没有可湿性粉剂的功能,但它很容易使你自己,例如

function return_image_path($thumbID) {

    $image= wp_get_attachment_image_src($thumbID);
    $imagepath= str_replace(get_site_url(), $_SERVER['DOCUMENT_ROOT'], $image[0]);

    if($imagepath) return $imagepath;

    return false;

}

根据David的回答,这对我很有用:

function return_image_path($thumbID) {
                    $thumbID = get_post_thumbnail_id( $post->ID );
                    $image= wp_get_attachment_image_src($thumbID);
                    $upload_dir = wp_upload_dir();
                    $base_dir = $upload_dir['basedir'];
                    $base_url = $upload_dir['baseurl'];
                    $imagepath= str_replace($base_url, $base_dir, $image[0]);
                    if ( file_exists( $imagepath) ) return $imagepath;
                    return false;
}

根据David的回答,这对我很有用:

function return_image_path($thumbID) {
                    $thumbID = get_post_thumbnail_id( $post->ID );
                    $image= wp_get_attachment_image_src($thumbID);
                    $upload_dir = wp_upload_dir();
                    $base_dir = $upload_dir['basedir'];
                    $base_url = $upload_dir['baseurl'];
                    $imagepath= str_replace($base_url, $base_dir, $image[0]);
                    if ( file_exists( $imagepath) ) return $imagepath;
                    return false;
}

您的意思是:wp\u get\u attachment\u image\u src您的意思是:wp\u get\u attachment\u image\u src非常接近,尽管代码假定WordPress安装在根目录中。然而,它确实让我找到了具有非常类似解决方案的wp_upload_dir函数。非常接近,尽管代码假定WordPress安装在根目录中。然而,它确实让我找到了具有非常类似解决方案的wp_upload_dir函数。