February 24, 2008

wp-o-matic quick & dirty duplicate post fix

Posted in Open Source, wordpress tagged , , , , , , at 12:23 am by ilanco

I’m getting a lot of duplicate posts using wp-o-matic and if you are reading this, you probably have the same problem.

Instead of fixing wp-o-matic (that’s the developer’s job) I just changed my local wordpress to ignore posts with the same title.

Here is how it works :

  1. Open up wp-includes/post.php in your favorite editor
  2. at approx line 703 you will find the following line :
    if ($post_name_check || in_array($post_name, $wp_rewrite->feeds) ) {
  3. After this insert a new line of code :
    return 0;
  4. save (you did make a backup, right?).
  5. All done.
Advertisements

57 Comments »

  1. An excellent solution.

    It worked right away. I tested it by using the Fetch link. I am hoping it’s the same when it works on its own — should do, because of the logic of your simple solution.

    And so easy to do, too.

    Many thanks.

    I’ve linked to this page from several other forums where folks with the same problem have asked for help.

    Gary

  2. amfprod said,

    So are the posts never created, or are they still created and just ignored?

  3. linuxil said,

    amfprod,

    The posts are never created because of a dupliacte title restriction. Normally wordpress would just add -1, -2, … and so on. Instead our patch just skips the post and moves on.

    Regards.

  4. Businessman said,

    An what about Mysql Base. The posts are in tables?

  5. linuxil said,

    There will be only 1 post with the same title in the database, no duplicates.

  6. thanks, it works great.

  7. gofree said,

    Very useful indeed.
    Now trying…
    Thx

  8. Jake said,

    I’m not sure if it’s because of this, but now it won’t fetch posts automatically.

  9. linuxil said,

    Jake, this patch does not change wp-o-matic. Unless you broke something while patching the file it should work.

    Good luck

  10. […] people are getting lots of duplicate posts using Wp-o-matic, this sexy dude found a quick […]

  11. Bryan said,

    I really need somone to help me with setting up my cron correctly. I cannot get WP-O-Matic to check automatically. I’d appreciate the help, I have looked everywhere and the developer of this plug-in is harder to reach than my ex-wife.

  12. linuxil said,

    Bryan, read the post and comments carefully. If you don’t find your answer try to post a comment with some helpful information se we can help you 🙂

    Good luck

  13. Bryan said,

    Your article and the comments that fallow have nothing to do with proper cron configuration, implementation or installation of the wp-o-matic plug-in — which is what I thought someone here might be willing to help me with.

    However, one question that is directly related to this post…
    Won’t the “fix” you are talking about keep any post with the same title from being published? Or am I missing something?

  14. linuxil said,

    You’re right, try the following url : wp-o-matic cron.

    As for the fix, yes it does keep from publishing 2 posts with the same title … which shouldn’t happen in any case …

    Regards

  15. Alexander said,

    Hello everyone!
    Linuxil, the code “if ($post_name_check || in_array($post_name, $wp_rewrite->feeds) ) {” is not place on line 703 anymore.. I found it at line 1200 something. And then I place the return 0; under it, and I still get those stupid duplicate posts… I think it’s because of the 2.5.1 version of WordPress??

    I hope you can help, because the developer can’t / won’t …

    Best regards,
    Alexander.

  16. […] I’ve been having of multiple posts coming in from my Twitter updates, I’m implementing this dirty WordPress hack to delete duplicate posts before we go to […]

  17. linuxil said,

    Hi Alexander,

    I did not test this fix on WordPress 2.5. I’m not sure wp-o-matic is compatible with 2.5. Anyway if you find a fix for 2.5 let us know.

    On a different topic : I think it’s too soon to start using WordPress 2.5. Let them work out all the bugs first and give the plugin developers a chance to test it out …

    Regards.

  18. STARTNET said,

    Hello I need wordpress to filter post titles.
    if somone trys to post with a title that is already in there. then it seaches and lets them add to that post with comments. No same post titles. it just searches first then lets you add. Is something like this possable?

  19. Doug said,

    Has anyone tried configuring wp-o-matic to cache images to Amazon S3? Been trying to figure it out.

  20. Jetsam said,

    Somehow i missed the point. Probably lost in translation 🙂 Anyway … nice blog to visit.

    cheers, Jetsam.

  21. Andrew said,

    just do a search and replace for

    $suffix = 2;

    and replace with

    return 0;

    there’s 2 instances in the post.php in 2.5.1.

    That’s it.

    I just tested – works great – try and post a duplicate title – it’ll say it posted – but it won’t.

  22. zlash said,

    This doesn’t work on WP 2.5 with WP o matic RC 3,
    I have found this: http://wordpress.org/support/topic/144106?replies=10
    If someone could please help me to sort out this duplicate post problem on WP.
    Thanks!

  23. Lolita Loco said,

    Worked like a charm, two days of hairpulling is over for me. 😀 (WP 2.5.1)

  24. Jimmy said,

    Here is a clean fix to the duplicate post issue:
    in wpomatic.php around line 622, replace
    $row = $wpdb->get_row(“SELECT * FROM `{$this->db[‘campaign_post’]}`
    WHERE campaign_id = {$campaign->id}, feed_id = {$feed->id}, hash = ‘$hash’ “);
    by
    $row = $wpdb->get_row(“SELECT * FROM `{$this->db[‘campaign_post’]}`
    WHERE campaign_id = {$campaign->id} AND
    feed_id = {$feed->id} AND hash = ‘$hash’ “);

    That’s it !

  25. Alex said,

    Thanks, works

  26. MD said,

    Any ideas here for the error 500 issue?

  27. SB said,

    None of these fixes work for 2.6 and WP-o-Matic 1.0RC4-6

  28. Good morning,
    I am writing with google translation, I’m french.

    I installed wp-o-matic to day and I encounter some problems article in double or even more.

    but the biggest problems is that I can no longer use wp-o-matic because it uses all the resources of the server to create 100 and 100 articles.

    I took out wp-o-matic by my ftp to suprimant files, since 3537 I have cancelled articles, lol.

    the problem is that every time I download files WP-o-Matic again while the 100 and 100 articles.

    what needs – to remove it again as the brand new beginning?

  29. Sascha said,

    Here I found a php script someone wrote… you can run manually by calling it via the URL, it deletes all duplicate posts.
    A little dangeroues, but for me the easiest work around until this bug will be fixed in wp-o-matic.

    http://bloke.org/php/wordpress-wp-o-matic-duplicate-posts-fix/

  30. matt said,

    fyi i tried implementing this excellent bit of code on wordpress 2.6.1 using wp-o-matic 1.0RC4-6 and it works like a charm … thanks!!!!!

    matt

    PS- the fix
    “return 0;”

    needs to go immediately after line 1340

    hint
    use search function in the editor to find the string
    “if ($post_name_check”
    if you cant find it manually….

  31. For v2.6.2 it goes after line 1333 : )

  32. […] were problematic because the items were being posted multiple times. I did some research and found a fix to this problem and since have been quite happy with the work flow. The first screencast below demonstrates how […]

  33. thecolor said,

    this option works and needs to be reimplemented with the upgrade to WP 2.7

    I just had to do it as my auto posts were going nuts!

    Replace $suffix = 2
    With return 0;

    You will find $suffix = 2 twice in wp-includes/post.php

  34. Thomas Phipps said,

    there is an issue with this fix with the new wp-o-matic,
    if you have meta data being entered from a feed it will enter it into post 0.
    which happens to be the post thats used for write.

    not really an issue if you only have 4 or 5 feeds coming in, but a site I’m working with has about 60 feeds, and after a bit of time an many attempts to duplicate the issue causes the post screen to almost freeze as it trys to import all that duplicate postmeta data.

  35. kyle said,

    Hello,

    great solution.

    I started using the custom post template under the options tab of the individual campaign settings (campaigns>edit>options>)

    now that I’m using the custom post template I am again getting duplicate posts…

    anyone else have this problem?

  36. […] Re: Help With W-P-OMatic Posting Twice I found a quick, easy solution here: wp-o-matic quick & dirty duplicate post fix Linux in Israel […]

  37. Daan said,

    Perfect on wp 2.7.1
    Thanks

  38. Pankaj said,

    Great Man.

    It worked like a charm.

    Thanks a lot. I have been looking for this for a long time.

    Thanks a ton man.

  39. Jenyum said,

    This really saves a lot of pain, thanks for the fix.

    Unfortunately, I can’t figure out where to put this in WordPress 2.8. Anyone have that figured out? There’s no directly corresponding line of code, and the duplicate post problem is back since my client upgraded.

  40. Jenyum said,

    I seem to have this working for 2.8 now. Had to follow the instructions in the comments for 2.5.1, and there are now three instances of $suffix = 2.

  41. Thomas said,

    Any update for 2.8? Thanks

  42. Ben said,

    This doesn’t seem to work after the wordpress 2.8 upgrade. Does anyone have a new fix?

  43. […] Credit for this fix: Linuxil […]

  44. Lozzo said,

    I do tested on v2.8.1 hope it’s works, thanks for the patch.

  45. Tom said,

    This isn’t working for me in 2.8.1

  46. Lozzo said,

    I on v2.81 reserved back to v2.71 play around and, tested more that 10 hours everything working good and fine.

    More than 3 months searching for a clued with double post at last I got it’s.

    Thanks all for this good share.

  47. tot29 said,

    Yeah, this doesn’t work in wordpress 2.8. Any fix?

  48. Gamesguy said,

    Not working for me on 2.84 after replacing all 3 instances of $suffix = 2.

    It is not appending numbers to the post names but somehow creating multiple posts with the same name. It also shows the multiple same posts when I try to view one of them.

    • Anand said,

      Just change wpomatic.php
      as below replace that fuction, before make a backupcopy

      function isDuplicate(&$campaign, &$feed, &$item)
      {
      global $wpdb;
      $hash = $this->getItemHash($item);
      $title=$item->get_title();
      $row = $wpdb->get_row(“SELECT * FROM $wpdb->posts wposts WHERE wposts.post_title = ‘$title’ “);
      return ($row->ID);
      }

  49. Rudi said,

    How if we create duplicate post manually?

    Example:
    I have old post with title: “matic”
    and now I create new post with title “matic”

    will WP automated discard this new post?

  50. Chris said,

    Yea no luck on W.P 2.8.4 with the suffix fix. Anyone have anything new? When I double post on purpose with the same title, it just re-writes the url automatically with /0/ as the permalink.

  51. halil said,

    can somebody write one for wordpress 2.85 please?

  52. cj said,

    Great posts never die.

    Here it is almost two years later and I just used this technique for a small private WordPress MU community; using MU 2.8.2 and Autoblogged 2.5.74 (instead of wp-o-matic, and I betcha it works with feedwordpress, too).

    Works great! Thank you, thank you!!!

  53. Jon said,

    Works for me on WP 2.9.2.

  54. Julie said,

    anyone have this working on wp 3.0.1

  55. Julie said,

    We just tried it with a couple of test feeds from CNN and the NYT and at first the fix looked like it worked but that latest couple of posts are duplicated again.

    BTW, we had to make the change in 3 places in the code and the code is slightly different than above.

    this is the code with the new line

    if ( $post_name_check || in_array( $slug, $feeds ) ) {
    return 0;

    if anyone has any suggestions on how to make this work please post it here.

    thanks

  56. Jin said,

    Hi,
    Is it possible to make this fix works on WP 3.0 or higher?
    Iere is what I tried :

    I tried to do the same on the new post.php code, but it just add /0/ to the url field when the duplicate post is created.
    ANd duplicate posts still appears in front….

    Thanks


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: