View Single Post
Old 06-09-2016, 07:20 AM  
klinton
So Fucking Banned
 
Industry Role:
Join Date: Apr 2003
Location: online
Posts: 8,766
yeah, thank you very much.... what do you mean that it only works for current posts ?
I would like to edit drafts (that are scheduled) that way too....Actually most of the posts are drafts...
any other idea how to do that using plugins like search regex and search and replace ? what is the syntax over there (PHP syntax, regex) to mark all text found in all posts and link it to some url ? any idea ?



Quote:
Originally Posted by sarettah View Post
Do you have access to MYSQL for the site? Either from the command line or something like PHPMyadmin?

If you do then your easiest solution is just to do it with a couple of sql calls, at least if all posts are going to all link to the same thing.

1. Make a copy of the wp_posts table.

create table wp_posts_backup select * from wp_posts

2. Make the changes to the wp_posts table.

update wp_posts set post_content='<a href="http://url_to_link_to_goes_here">' + trim(post_content) + '</a>'

Now all posts should be linked to whatever url you specified.

There is danger in there if you have any quotation marks(") within the post_content itself. In that case the query would have to be worked a bit to handle that.

If you want to selectively update posts, meaning when you have something in the text go to one url and when you have something else go to another url then you would use the where clause to designate what's what.

example. update anything that mentions cams.com to link to your cams.com url and anything that mentions chaturbate to link to your chaturbate url.

Cams.com update: update wp_posts set post_content='<a href="http://cams.com_url_goes_here">' + trim(post_content) + '</a>' where post_content like '%cams.com%'

Chaturbate update: update wp_posts set post_content='<a href="http://chaturbate.com_url_goes_here">' + trim(post_content) + '</a>' where post_content like '%chaturbate.com%'

You could also handle multiple conditions within one query by using a case statement:

update wp_posts set post_content='<a href="' +
case
when instr(post_content,'chaturbate.com')>0 then 'http://chaturbate.com_url_goes_here'
when instr(post_content,'cams.com')>0 then 'http://cams.com_url_goes_here'
else
'http://default_url_goes_here'
end
+ '">' + trim(post_content) + '</a>'

There are many other ways to do it but these are probably the most straight forward.

If you go back to the site and no posts show then you got something wrong in there and you need to look at the post text and debug to figure out what you need to do. If needed you drop back to the backup table.

This takes care of the posts currently on the site. It does NOT take care of future posts.

This can all be very dangerous. USE AT YOUR OWN RISK AND DON'T COME BLAMING ME IF YOU FUCK IT UP.

I also do not guarantee the syntax as I wrote it. I did it off the top of my head and I could have a quote mark or apostrophe wrong in there. I always suggest you test stuff and make sure you have it write before committing yourself. As always the information contained in this post might be worth exactly what you paid for it.

Hope that helps.

.
klinton is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote