作为补充,作为对不同图像大小的改进,我会:
$file_name = pathinfo( $file, PATHINFO_FILENAME );
$file_extension = \'.\' . pathinfo( $file, PATHINFO_EXTENSION );
而是将
$file
.
并将SQL准备更改为:
$prepared_sql =
$wpdb->prepare(
$sql,
$id,
"%src=\\"%"
. like_escape( $file_name )
. "%"
. like_escape( $file_extension )
. "\\"%"
);
作为第二个添加的示例,使用MySQL的REGEXP
/RLIKE
功能,它还可以在a
标签,除此之外,它还能够——与第一个加法相反,第一个加法只获取完整的上传大小——获取独立于图像大小的图像——例如,»图像。jpg«将是全尺寸和»image-150x150。jpg«生成的尺寸-使用:
$file_name = pathinfo( $file, PATHINFO_FILENAME );
// beware different syntax
$file_extension = \'[[...]]\'.pathinfo( $file, PATHINFO_EXTENSION );
$sql = "SELECT {$wpdb->posts}.ID
FROM {$wpdb->posts}
INNER JOIN {$wpdb->postmeta}
ON ({$wpdb->posts}.ID = {$wpdb->postmeta}.post_id)
WHERE {$wpdb->posts}.post_type IN (\'post\', \'page\', \'event\')
AND (({$wpdb->posts}.post_status = \'publish\'))
AND ( ({$wpdb->postmeta}.meta_key = \'_thumbnail_id\'
AND CAST({$wpdb->postmeta}.meta_value AS CHAR) = \'%d\')
OR ( {$wpdb->posts}.post_content REGEXP %s )
)
GROUP BY {$wpdb->posts}.ID";
$exp =
\'([[.<.]])\' // tag start
. \'(img|a)\' // define tag types
. \'.*\' // other attributes void
. \'(src|href)\' // define anchor(s) attribute
. \'=([[.".]]|[[.\\\'.]])\' // quotes
. \'.*\' // path/URL void
. $file_name
. \'.*\' // image size void
. $file_extension
. \'([[.".]]|[[.\\\'.]])\' // quotes
. \'.*\' // other attributes void
. \'([[.>.]])\' // tag end
;
$prepared_sql =
$wpdb->prepare(
$sql,
$id,
$exp
);
$post_ids = $wpdb->get_results( $prepared_sql );