foreach( $posts as $post ) {
// Search for images and fill the missing dimensions in the current post content
$post_content = $this->add_image_dimensions( $post->post_content );
// Update the post content in the database only if the new $post_content it is not the same
// as the current $post->post_content
if( $post_content != $post->post_content ) {
$query = "UPDATE " . $wpdb->prefix . "posts SET post_content = \'" . $post_content . "\' WHERE ID = " . $post->ID;
$wpdb->query( $query );
}
// Add a post meta to the current post to mark it as doone
update_post_meta( $post->ID, \'image_dimensions_filled\', 1 );
如果有
\\
文字中的字符,然后它就会消失。如何修复它?
这是正确的吗?
...
if( $post_content != $post->post_content ) {
$post_content = wp_slash($post_content);
$query = "UPDATE " . $wpdb->prefix . "posts SET post_content = \'" . $post_content . "\' WHERE ID = " . $post->ID;
...
此变体不起作用。
$wpdb->query( $wpdb->prepare( $query ));
对不起,我的英语不好。