您可以从Url获取文件,如下所示:
//get the URL from your Metafield, $post is your current Post
$image = get_post_meta( $post->ID, \'_your_image_url_meta\', true );
//set up a query to search your posts table for the Url
global $wpdb;
$query = "SELECT ID FROM $wpdb->posts WHERE guid = %s LIMIT 1";
//prepare and launch the query
$result = $wpdb->get_results( $wpdb->prepare( $query, $image ) );
//if there are results
if ( count ( $result ) > 0 ) {
$image_id = $result[\'0\']->ID;
//get the image data
$image_data = get_post_meta( $image_id, \'_wp_attachment_metadata\', true );
}
您需要的所有信息现在都可以在
$image_data
. 请记住,您可能需要稍微更改脚本—例如,如果您的作者输入了一个缩略图url,您必须首先清理它,然后将查询更改为
LIKE
陈述