Wordpress MySQL help

guerilla

All we do is win
Aug 18, 2007
11,426
428
0
No
I did a ton of posts in DataPresser. They have been auto posting and queued for months now.

The problem is, I embedded an unordered list block at the bottom of each post, and now I wish I hadn't, because I hardcoded URLs and text in there.

So in each post, I have

Code:
<ul>
<li><a href="hxxp://site.com/go/123/">123</a></li>
<li><a href="hxxp://site.com/go/456/">456</a></li>
<li><a href="hxxp://site.com/go/789/">789</a></li>
<li><a href="hxxp://site.com/go/136//"><strong>136</strong></a></li>
</ul>
In every post, this block of text is the same. Identically the same.

I have no other unordered lists in my posts. This is the only one.

Is there a way to run a query on my posts (published and scheduled) to remove this block?

Either to trim the last X characters off the end of each post, or to do some sort of regex match?

We're looking at the wp_posts table and the post_content column.

Any help would be appreciated. +Rep for help. TIA.
 


Use substr() to remove characters from the end of the string.

$rest = substr("abcdef", 0, -1);
echo $rest;

// returns "abcde"
 
  • Like
Reactions: guerilla
I hope that your username refers to F.A. and not Salma!

Thanks for the php help, but it is useless to me because my code-jitsu is weak.

Ideally, there is a MySQL query to run.
 
Ideally, there is a MySQL query to run.

I don't think there is. There's a REGEXP function that you can use to match, but I don't think you can replace. I'll try to post some PHP later or tomorrow if someone else doesn't first.

The most obvious way is to select the id and content fields from rows, using the Mysql REGEXP function or LIKE operator to match. Then looping over those rows, replacing the string in a PHP loop, then updating the row with an sql query.
 
Maybe I should just do this in Textpad. Dump the Table, run a find and replace with regex...

Don't spent any time on this yet LF. I might be able to do it ad hoc.

Thanks guys!
 
@noman, I don't understand your question.



@all, I did this with Textpad. TP rocks.

For future reference, I dumped the table through PhpMyAdmin with UPDATE statements.

I opened the SQL file in Textpad

Did a F8 Find and replace, used regex

Find
Code:
<ul>.*</ul>
Replace (with nothing)

Saved the SQL. Imported the SQL file back into my DB.

Thanks!!