由于错误,图像标题的href错误。用图像源替换href的最佳方法是:
post content [caption id="attachment_4900" align="aligncenter" width="600"]
<a href="wrong_url"><img class="size-full wp-image-4900" src="correct_source" alt="text" /></a>
text[/caption]
更新:这是我正在使用的代码,但它没有给出期望的结果。相反,最终的结果是
test
我不知道它是从哪里来的:
function updateposts() {
global $post;
$fh_import = @fopen( dirname( __FILE__ ) . \'/file.txt\', \'r\' );
if ( $fh_import ) {
while ( ( $line = fgets( $fh_import ) ) !== false ) {
$ids = explode( \'*\', $line );
array_walk( $ids, \'trim\' );
$newcontent = preg_replace(\'/href="(.+?)"(.+?)src="(.+?)"/\', \'href="$3"$2src="$3"\', $post->post_content);
$newpost = array(
\'ID\' => $ids[0],
\'post_content\' => $newcontent
);
wp_update_post( $newpost, $wp_error );
}
}
}