wordpress help - link all texts in al posts

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • klinton
    So Fucking Banned
    • Apr 2003
    • 8766

    #1

    wordpress help - link all texts in al posts

    So basically I would like to bulk edit all posts that I have and link whole text that is in every post to some url....
    how to do that ? please dont post answers with plugins like search regex, search and replace and so on..unless you know exact php syntax to do this task... in that case - you are very welcome, thx
  • sarettah
    see you later, I'm gone
    • Oct 2002
    • 14301

    #2
    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.

    .
    All cookies cleared!

    Comment

    • klinton
      So Fucking Banned
      • Apr 2003
      • 8766

      #3
      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 ?



      Originally posted by sarettah
      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.

      .

      Comment

      • sarettah
        see you later, I'm gone
        • Oct 2002
        • 14301

        #4
        Originally posted by klinton
        yeah, thank you very much.... what do you mean that it only works for current posts ?
        It means that the sql is only going to change posts that are currently in the database. It is not going to automatically do anything to future posts. They do not exist yet so they will not be changed.

        I have no idea on what plugins you might use for this going forward.

        As far as doing it to a post that you are writing then just include the link when you create the post I would think.

        I just tested on one of my wife's wp installs and it worked just fine. The posts I made was:

        <a href="http://url_to_use.com">This is a test post</a>

        It made a post that was linked.


        .
        All cookies cleared!

        Comment

        • sarettah
          see you later, I'm gone
          • Oct 2002
          • 14301

          #5
          Ok, I had missed that you said posts that are scheduled. YES, those would be changed in the method I outlined using sql calls.

          All posts in the posts table could/would be affected. Scheduled posts are in the posts table with a future date so they would be changed.

          Sorry I missed that part in my answer.

          .
          All cookies cleared!

          Comment

          • klinton
            So Fucking Banned
            • Apr 2003
            • 8766

            #6
            who would expect that ?

            any idea on php regex to mark whole text in posts ? in MS-DOS system it was usually *.*, but how about PHP ?
            Originally posted by sarettah
            It means that the sql is only going to change posts that are currently in the database. It is not going to automatically do anything to future posts. They do not exist yet so they will not be changed.
            .

            Comment

            • sarettah
              see you later, I'm gone
              • Oct 2002
              • 14301

              #7
              Originally posted by klinton
              who would expect that ?

              any idea on php regex to mark whole text in posts ? in MS-DOS system it was usually *.*, but how about PHP ?

              I am not sure what you are asking. I understand regex, I understand php, I even understand your wildcard using DOS. But I do not understand how you are thinking to use regex when changing posts.

              The posts are in a database so they either have to be changed while they are going in or when they come out (being displayed).

              I do not see either of those requiring regex although if you modified the php being used to display the posts as they come out you could use regex in there but there are other ways to do it too.

              What are you wanting the regex to match to? Meaning, are you changing things conditionally (as I described above where one goes to cams and the other to chaturbate) or is everything going to link to the same thing or what?

              Sorry for seeming dense.

              .
              All cookies cleared!

              Comment

              • klinton
                So Fucking Banned
                • Apr 2003
                • 8766

                #8
                there is one wordpress plugin called "search regex" which is handful for me.
                yesterday I used it to bulk modify all posts that contained some url like url.com/variablehere to steadyurl.com
                I did it using some PHP magic delimiter like
                Code:
                /<a [^>]+>/i
                which basically searched for all urls in posts, marked them and changed them to my new url, specified before in the plugin field "replace with"...
                now, my queston is: what would be PHP delimiter to mark whole text in that plugin and later modify it with adding just
                Code:
                <a href="http://www.myurl.com">
                at the beginning.
                is it even possible ?
                I prefer to use that plugin instead of php my admin somehow, it has safe option like just "search" "search and replace without saving" and so on
                Originally posted by sarettah
                I am not sure what you are asking. I understand regex, I understand php, I even understand your wildcard using DOS. But I do not understand how you are thinking to use regex when changing posts.

                The posts are in a database so they either have to be changed while they are going in or when they come out (being displayed).

                I do not see either of those requiring regex although if you modified the php being used to display the posts as they come out you could use regex in there but there are other ways to do it too.

                What are you wanting the regex to match to? Meaning, are you changing things conditionally (as I described above where one goes to cams and the other to chaturbate) or is everything going to link to the same thing or what?

                Sorry for seeming dense.

                .

                Comment

                • sarettah
                  see you later, I'm gone
                  • Oct 2002
                  • 14301

                  #9
                  Originally posted by klinton
                  there is one wordpress plugin called "search regex" which is handful for me.
                  yesterday I used it to bulk modify all posts that contained some url like url.com/variablehere to steadyurl.com
                  I did it using some PHP magic delimiter like
                  Code:
                  /<a [^>]+>/i
                  which basically searched for all urls in posts, marked them and changed them to my new url, specified before in the plugin field "replace with"...

                  now, my queston is: what would be PHP delimiter to mark whole text in that plugin and later modify it with adding just
                  Code:
                  <a href="http://www.myurl.com">
                  at the beginning.

                  is it even possible ?

                  I prefer to use that plugin instead of php my admin somehow, it has safe option like just "search" "search and replace without saving" and so on
                  I don't know anything about that plugin, sorry about that. However the regex expression to match everything should be .* (dot and asterick).

                  .
                  All cookies cleared!

                  Comment

                  • johnnyloadproductions
                    Account Shutdown
                    • Oct 2008
                    • 3611

                    #10
                    Klinton I sent you a PM with my info, read it.

                    Contact the email if you have interest.

                    I can fix all the current links but won't be doing anything for future links.

                    Comment

                    • moln4r
                      Confirmed User
                      • Apr 2010
                      • 146

                      #11
                      If you want contextual links there is a plugin I used somewhere in 2010 what can link any word in the whole site to any url.drop a pm if interested i do search for it.
                      Webcam Performers Wanted
                      Cheap Dedicated Servers
                      Affiliate revenue calculator
                      Make as much $$$ as you want

                      Comment

                      • klinton
                        So Fucking Banned
                        • Apr 2003
                        • 8766

                        #12
                        got one already that is called "seo autolinker"... however, the thing is that I actually would like to link whole text in all posts to some url....
                        so it looks like that I will have to do it via php my admin....
                        if you know how to do it in search regex plugin or search and replace plugin, you may let me/us know ;]
                        Originally posted by moln4r
                        If you want contextual links there is a plugin I used somewhere in 2010 what can link any word in the whole site to any url.drop a pm if interested i do search for it.

                        Comment

                        • SpeedoDave
                          Confirmed User
                          • Sep 2003
                          • 354

                          #13
                          Sarettah,
                          Awesome response mate.
                          Dave

                          QUOTE=sarettah;20951015]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.

                          .[/QUOTE]
                          I feel old since I started SpeedoFetish.com back in 2001.

                          Comment

                          • sarettah
                            see you later, I'm gone
                            • Oct 2002
                            • 14301

                            #14
                            Originally posted by SpeedoDave
                            Sarettah,
                            Awesome response mate.
                            Dave
                            Except that I screwed up a bunch of syntax. My brain fell away from mysql and dropped back to a different sql that understands + as the concat operator.

                            Oh well.

                            So every where that I did the + in the queries should have used a concat() function instead.

                            I also should have a where condition to see if post_content has anything in it.

                            So, the examples I used up there will not work and instead need to look like this:


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

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

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

                            update wp_posts set post_content=concat('<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>') where trim(post_content)>''


                            I hate when I fuck up like that. It seems to happen about 4 billion times a day

                            .
                            All cookies cleared!

                            Comment

                            Working...