Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

How to remove few lines from wordpress post using phpmyadmin WordPress

Hi

i want to remove few lines in my WordPress posts, this i wanna do in phpmyadmin
i have more than 4000 + posts so if i am doing manually its very difficult
any one please give give me suggestion

i know find and replace that i wanna do one by one

i am expecting to remove few blocks for example begin text to end text

waiting for earlier response

Regards

Answers (3)

2013-11-24

Hariprasad Vijayan answers:

Hello,

Do you want to remove lines from all this 4000 posts? Are you searching for a sql query?

This may help you if you are searching for a sql query.

http://www.mydigitallife.info/how-to-find-and-replace-text-in-mysql-database-using-sql/
http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_replace


anitha comments:

@ Hariprasad

Hi Hariprasad thanks for the reply
yes you are right i am searching for sql query, but those given links mydigitallife didn't helped me
second link i don't know which one i wanna try

my requirement is to remove a block begin text to end text on some paragraph

if you give any suggestion it will be very helpful



Hariprasad Vijayan comments:

Okay.

You can see the details in first thread.

The code should be like this. Not tested this. Take proper backup of database before execute query.

update wp_posts set post_content = replace(post_content, ‘string to remove’, ‘’);

And this is only applicable if you want to remove similar lines from all posts.

Please let me know if you need any further doubt in this.


anitha comments:

@ Hariprasad

thanks for the reply

its not similar lines, its different lines, so the above query not suitable i think

is there any queries to remove specific div completely for example <div id='header-wrapper'> to </div>




Hariprasad Vijayan comments:

I think this is not possible using sql query, and it is possible by a php script.

you can try something like


<?php
global $wpdb;
$result = $wpdb->get_results("SELECT `ID` , `post_content` FROM $wpdb->posts");
foreach ($result as $post) {
$postid = $post->ID;
$post_content = $post->post_title;
$new_content = preg_replace('/(<div.*?id="header-wrapper"[^>]*>)(.*?)(<\/div>)/i', '$1$3', $post_content);
$wpdb->query("UPDATE $wpdb->posts SET post_content = '".$new_content."' WHERE ID = ".$postid);
} ?>


Hariprasad Vijayan comments:

There is a mistake in my previous comment

code would be like this

<?php
global $wpdb;
$result = $wpdb->get_results("SELECT `ID` , `post_content` FROM $wpdb->posts");
foreach ($result as $post) {
$postid = $post->ID;
$post_content = $post->post_content;
$new_content = preg_replace('/(<div.*?id="header-wrapper"[^>]*>)(.*?)(<\/div>)/i', '$1$3', $post_content);
$wpdb->query("UPDATE $wpdb->posts SET post_content = '".$new_content."' WHERE ID = ".$postid);
} ?>

Let me know if you have any doubt in this.


anitha comments:

@ Hariprasad

thanks for the php script

i tried its removing whole post, its not removing the particular div


Hariprasad Vijayan comments:

that code is for removing a div with id "header-wrapper". could you show exact content that you want to remove.

check your PM.

2013-11-24

Just Me answers:

To give exact instructions you will have to supply more details but in general this command will find and replace text in a field_name, then save the new value to field_name. Your "find" is the string you are looking for, your "replace" should be "" (empty string).

update TABLE_NAME set FIELD_NAME = replace(FIELD_NAME, ‘find this string’, ‘replace found string with this string’)

Make sure to backup your database before executing commands like this.


anitha comments:

@ Just me

thanks for the reply

find and replace it won't work for my issue, coz in 4000 posts all the sentence are not same it have different combination so i want to find and replace one by one, i need solution like remove from this word to that word,is that possible


Just Me comments:

With preg_match in the above given code use

$new_content = preg_replace('/(.*)(<div id='head-wrapper'>)(.*)(<\/div>)(.*)/i', '$1$5', $post_content);


Assuming there are no other div's inside the head-wrapper div.

2013-11-25

Balanean Corneliu answers:

I can give you a script to make this take the code from here http://colibry.ro/replacecode and insert in a new php file on your server : after access the file like yoururl/youphpfilename.php and go ahead with the steps.
Good luck, make a backup of your DB first ;)


Balanean Corneliu comments:

This code is good to change the url to if you have broken url can use it to transform the url's to the good ones,
Ex. from http://exemple.com/cars/firstcars/productname
to http://exemple.com/car/productname