Apologies if this has been mentioned elsewhere, however I have a query regarding wildcards.
I have setup another Wordpress installation with a new responsive theme. I have imported all of the posts, and I have noticed that one of the authors has ‘positioned’ elements by using code similar to:
I also think you don’t want to delete those posts, you just want to remove the HTML markup from the posts, is that correct? As if that is the case, it “may” be easier to do this via PHP than within MySQL
No I don’t want to delete the posts, just the HTML that begins with <p><a href and ends in </a></p> that contains BLANK-SPACE.JPG somewhere in the middle.
Okay, so something along the lines of this would work (if you don’t have any PHP knowledge, I can write up a more workable example later tonight)
// connect to your database
// run query SELECT POST_ID, CONTENT FROM TABLE_NAME WHERE COLUMN_NAME LIKE '%BLANK-SPACE.jpg%'
// Loop through each record and run the POST CONTENT through the following code
$updatedContent = preg_replace('/\\\\<a href="(.*)"(.*)\\\\>\\\\<img src="(.*)BLANK-SPACE.jpg"(.*)\\\\/\\\\>\\\\<\\\\/a\\\\>/', '', '$row['CONTENT']');
// run query UPDATE TABLE_NAME SET COLUMN_NAME = '$updatedContent' WHERE post_id = $row['POST_ID']
Hopefully this goes without saying, but BACKUP YOUR DATABASE before using this.
Then paste the following in a file named cleanup.php
<?php
require_once('wp-config.php');
$pdo = new PDO('mysql:host='.$DB_HOST.';dbname='.$DB_NAME.';charset=UTF-8', $DB_USER, $DB_PASSWORD);
$postsAffectedQuery = $pdo->prepare(sprintf("SELECT ID, post_content FROM %sposts WHERE post_content LIKE ?", $table_prefix));
$postsAffectedQuery->execute('%BLANK-SPACE.jpg%');
$postsAffected = $postsAffectedQuery->fetchAll();
foreach ($postsAffected as $post)
{
echo sprintf('Updating POST ID = %s ... ', $post['ID']);
$updatedContent = preg_replace('/\\\\<a href="(.*)"(.*)\\\\>\\\\<img src="(.*)BLANK-SPACE.jpg"(.*)\\\\/\\\\>\\\\<\\\\/a\\\\>/', '', $post['post_content']);
try
{
$updatePostQuery = $pdo->prepare(sprintf("UPDATE %sposts SET post_content = ? WHERE ID = ?", $table_prefix));
$updatePostQuery->execute($updatedContent, $post['ID']);
echo 'Success!<br />' . PHP_EOL;
}
catch(PDOException $e)
{
echo sprintf('Failed with %s<br />%s', $e->getMessage(), PHP_EOL);
}
}
?>
Upload it to the same folder your wp-config.php file exists in.
Then open that file in your browser using www.mydomain.com/cleanup.php (or wherever it is installed, change the url accordingly to your website)