for Each post, the content is seperated by tabs for example:
<blockquote>[tab: XXXX 1]
Description 1
[tab: XXXX 2]
Description 2
[tab: XXXX 3]
Description 3</blockquote>
I Want to know if its possible to replace these tabs with <!--nextpage-->
I tried using phpmyadmin by replacing [tab: with <!--nextpage--> but the first page would be empty since the content will look like
<blockquote><!--nextpage--> XXXX 1]
Description 1
<!--nextpage--> XXXX 2]
Description 2
<!--nextpage--> XXXX 3]
Description 3
</blockquote>
Ozh RICHARD answers:
You need to use regular expressions (regexp) and match your "[tab: XXX Y]". MySQL doesn't know how to replace strings with regexp, so yo have to craft a PHP script that does the replacement in each post (I'm not writing it for $4 though :)
Ozh RICHARD comments:
Of course I'm assuming here that when you write "[tab: XXX 1]", the "XXX" can be anything and a different string each time.
If it's always the same string, then you can do it in phpMyAdmin:
- replace "[tab: XXX 1]" with "<!--nextpage-->"
- replace "[tab: XXX 2]" with "<!--nextpage-->"
- and so on
Marvin Shaker comments:
I WIll Pay up to 50$ if you can do it.
Oh and I Have over 16,000 Posts so the above code will take forever
updated example
From
[tab:Sapo Mirror]
<div class="parts">Part 1</div>
[sapo]mdTsySRL3NwF2PoZpYd[/sapo]
<div class="parts">Part 2</div>
[sapo]2GqZ5qSoj4vyCQfUTwO[/sapo]
[tab:Videoweed Mirror]
<div class="parts">Part 1</div>
[videoweed]0v7lgmjxubux[/videoweed]
<div class="parts">Part 2</div>
[videoweed]5vakao1sxwel[/videoweed]
[tab:Google Mirror]
<div class="parts">Part 1</div>
[google]mdTsySRL3NwF2PoZpYd[/google]
<div class="parts">Part 2</div>
[google]2GqZ5qSoj4vyCQfUTwO[/google]
to
<div class="parts">Part 1</div>
[sapo]mdTsySRL3NwF2PoZpYd[/sapo]
<div class="parts">Part 2</div>
[sapo]2GqZ5qSoj4vyCQfUTwO[/sapo]
<!--nextpage-->
<div class="parts">Part 1</div>
[videoweed]0v7lgmjxubux[/videoweed]
<div class="parts">Part 2</div>
[videoweed]5vakao1sxwel[/videoweed]
<!--nextpage-->
<div class="parts">Part 1</div>
[google]mdTsySRL3NwF2PoZpYd[/google]
<div class="parts">Part 2</div>
[google]2GqZ5qSoj4vyCQfUTwO[/google]
Ozh RICHARD comments:
OK, script on its way.
Ozh RICHARD comments:
Please try this: http://pastebin.com/xT6qyp3F
Save this script as "marvin.php" for instance and put it in your WordPress root directory (where wp-load.php is) then load it in your browser.
What the script does:
- Load 50 posts, verify if each post needs to be updated (ie contains the [tab..] stuff) and update if necessary.
- Then the script pauses for 1 second to avoid server hammering,
- Then loads the next 50 posts, and so on till there's no more posts
Yes, it will take quite some time. There's no other way.
If your server is strong & fast enough, you can increase that number from 50 to 100, 150, 200... Edit the beginning of the script and modify the value of $marv_chunk. If you put a too big number, the page will simply die in a timeout. In such a case, edit again, put a lower number, and simply reload the page.
Additional feature: I thought it would be a good idea not to get entirely rid of the content of the [tab...] (for example, in case you decide in the future to edit all posts again with another syntax. Always think future proofness, it makes life easier).
So, for instance, "[tab:Sapo Mirror]" will be replaced with "<!--nextpage--><!--marvin:Sapo Mirror-->"
If you don't want that extra HTML comment, remove "<!--marvin:\\1-->" from $marv_replace in the script.
Ozh RICHARD comments:
Additional comment: make sure you have a backup of your DB before launching the script. Safety never hurts....
Ozh RICHARD comments:
Additional comment again: of course, you can check if that works before waiting the 2 hours or so that it'll take. Load the script, and when the first batch of posts has been updated, check your blog's frontpage. If it looks ok, let the script run. If it looks not ok, close the webpage running the script and give me details.
Another feature of the script is: if for any reason a post should be updated but there was an error doing so, the script will create a file named marv-error.log in the same directory. You'll get there a list of post ID that were faulty. It's very unlikely to happen but I thought it would not hurt.
Ozh RICHARD comments:
Last comment: when I do freelancing, I usually ask for half payment upfront, then the rest on product delivery. I hope I'll be happy to have been trustful here :)
Marvin Shaker comments:
Uhm the Script works but it only does the changes to 351 posts
Ozh RICHARD comments:
Paste the content of a post that was unchanged but should have.
Also, the script loops through *posts* (not *pages*, or any other custom post type)
Marvin Shaker comments:
it runs the same posts over and over
unless i do
marvin.php?start=2 // this will update the next posts
marvin.php?start=3 // this will update the next posts
is this how its supposed to work?
Ozh RICHARD comments:
The page reloads automatically with the next batch of posts (there is a tiny javascript bit, see screenshot attached), unless the script has died in the meantime (and if so, decrease $marv_chunk)
$marv_chunk
Ozh RICHARD comments:
(bleh, forgot sshot)