WordPress.org

Ready to get started?Download WordPress

Forums

WPeMatico
Checking for duplicates based on permalink rather than title doesnt work (9 posts)

  1. RobertHarm
    Member
    Posted 2 years ago #

    I use WPeMatico 0.8beta to gather RSS feeds for events and save new posts as draft. On nearly every post we have to change the title and so on each new WPeMatico run the post gets imported again :-(

    I looked in wp-content/plugins/wpematico/app/wpematico_dojob.php and found on line 174 the following code:

    private function isDuplicate(&$campaign, &$feed, &$item) {
    	// Agregar variables para chequear duplicados solo de esta campaña o de cada feed ( grabados en post_meta) o por titulo y permalink
    		global $wpdb, $wp_locale, $current_blog;
    		$table_name = $wpdb->prefix . "posts";
    		$blog_id 	= $current_blog->blog_id;
    		$title = $item->get_title();// . $item->get_permalink();
    		$query="SELECT post_title,id FROM $table_name
    					WHERE post_title = '".$title."'
    					AND ((<code>post_status</code> = 'published') OR (<code>post_status</code> = 'publish' ) OR (<code>post_status</code> = 'draft' ) OR (<code>post_status</code> = 'private' ))";
    					//GROUP BY post_title having count(*) > 1" ;
    		$row = $wpdb->get_row($query);
    		trigger_error(sprintf(__('Checking duplicated title \'%1s\'','wpematico'),$title).': '.((!! $row) ? __('Yes') : __('No')) ,E_USER_NOTICE);
    		return !! $row;
      }

    So I tried to implement the duplicate check based on permalink, but I might have forgotten something, as the following code doesnt work - any help/hint is appreciated!

    private function isDuplicate(&$campaign, &$feed, &$item) {
    	// Agregar variables para chequear duplicados solo de esta campa?a o de cada feed ( grabados en post_meta) o por titulo y permalink
    		global $wpdb, $wp_locale, $current_blog;
    		$table_name = $wpdb->prefix . "posts";
    		$blog_id 	= $current_blog->blog_id;
    		$title = $item->get_permalink();
    		$query="SELECT post_name,id FROM $table_name
    					WHERE '".$title."' like '%post_name%'
    					AND ((<code>post_status</code> = 'published') OR (<code>post_status</code> = 'publish' ) OR (<code>post_status</code> = 'draft' ) OR (<code>post_status</code> = 'private' ))";
    					//GROUP BY post_title having count(*) > 1" ;
    		$row = $wpdb->get_row($query);
    		trigger_error(sprintf(__('Checking duplicated title \'%1s\'','wpematico'),$title).': '.((!! $row) ? __('Yes') : __('No')) ,E_USER_NOTICE);
    		return !! $row;
      }

    http://wordpress.org/extend/plugins/wpematico/

  2. wongkediri
    Member
    Posted 2 years ago #

    i guest problem on WHERE clause, it should be

    WHERE post_name LIKE '%".$title."%'

  3. wongkediri
    Member
    Posted 2 years ago #

    UPDATE:
    above code not working, if title has some special character it won't work.
    i try myself on my site and best approach is here:

    private function isDuplicate(&$campaign, &$feed, &$item) {
    	// Agregar variables para chequear duplicados solo de esta campaña o de cada feed ( grabados en post_meta) o por titulo y permalink
    		global $wpdb, $wp_locale, $current_blog;
    		$table_name = $wpdb->prefix . "posts";
    		$blog_id 	= $current_blog->blog_id;
    		$title = $item->get_title();// . $item->get_permalink();
    		$query="SELECT post_title,post_name,id FROM $table_name
    					WHERE post_name LIKE '".sanitize_title_with_dashes($title)."%'
    					AND ((<code>post_status</code> = 'published') OR (<code>post_status</code> = 'publish' ) OR (<code>post_status</code> = 'draft' ) OR (<code>post_status</code> = 'private' ))";
    					//GROUP BY post_title having count(*) > 1" ;
    		$row = $wpdb->get_row($query);
    		trigger_error(sprintf(__('Checking duplicated title \'%1s\'','wpematico'),$title).': '.((!! $row) ? __('Yes') : __('No')) ,E_USER_NOTICE);
    		return !! $row;
      }

    please look at changed code below:

    WHERE post_name LIKE '".sanitize_title_with_dashes($title)."%'

    it will check duplicate permalink and version, that's why i just using '%' at the end

  4. RobertHarm
    Member
    Posted 2 years ago #

    thanks for the code - unfortunately it didnt work at all for me - posts from each campaign were imported again on each run even if I didnt change the title or permalink at all.

    I first guessed it was because your code was changed through the editor on wordpress.org-forums:
    AND ((<code>post_status</code> = 'published') OR (<code>post_status</code> = 'publish' ) OR (<code>post_status</code> = 'draft' ) OR (<code>post_status</code> = 'private' ))";

    I changed this line to
    AND ((post_status = 'published') OR (post_status = 'publish' ) OR (post_status = 'draft' ) OR (post_status = 'private' ))";
    but unfortunately with no effect.

    Can you please check your code again? I also didnt get it what I have to do if I just want to do a check on changed permalinks only. In your code example does that mean I have to change
    $title = $item->get_title();// . $item->get_permalink();
    to
    $title = $item->get_permalink();// . $item->get_permalink();

    Thanks again for your help!

  5. wongkediri
    Member
    Posted 2 years ago #

    Hi, sorry. i didn't notice that. thanks for editing.

    yes, i m checking duplicate on permalink because its more precise.

    I have try several method but below is the best approach.
    now i m checking if permalink is exist. but not using permalink from $item object, I m using wordpress built in function that convert title to permalink, sanitize_title_with_dashes().

    after generating permalink from title, change the query to search duplicate permalink.

    if using code below, and still post duplicate, usually its just only one dupes. because you already has dupe post with numeric value added in the end of permalink.

    example:
    http://domain.tld/your-post-permalink-1.html
    http://domain.tld/your-post-permalink-2.html

    complete code please check here. hope its more clear.
    http://pastebin.com/sV6V35vB

  6. RobertHarm
    Member
    Posted 2 years ago #

    Hi again & thanks for the code - unfortunately it still doesnt work :-(

    I tried a few things - here´s what I found out: I made a campaign with the url http://ebc.apa.at/cms/ebc/events_rss.rss - each run imports 3 items as drafts. After creating the campaign I run it manually and 3 items get imported. I then run it again manually and again 3 items get imported. I have to change the status of one draft to published in order to not import (all) posts again.

    First I thought it had to do with the query, as your code doesnt select post_status:
    $query="SELECT post_title,post_name,id FROM $table_name
    so I changed this line to
    $query="SELECT post_title,post_name,id,post_status FROM $table_name
    - unfortunately with no effect.

    I also thought it might have to do with the line
    AND ((post_status= 'published') OR (post_status= 'publish' ) OR (post_status= 'draft' ) OR (post_status= 'private' ))";
    so I changed this line to

    AND ((post_status = 'published') OR (post_status = 'publish' ) OR (post_status = 'draft' ) OR (post_status = 'private' ))";

    - unfortunately again with no effect.

    Any additional help would be very appreciated!

  7. wongkediri
    Member
    Posted 2 years ago #

    i m trying your rss source using wpematico default install and its working fine.
    no duplicate post after running several time.

  8. bspr3663
    Member
    Posted 2 years ago #

    I tried the code as well and found it to help (so I think), but it is still making duplicates. Judging from the duplicates I can't pin point it to why, meaning a specific character. Some titles were different, some were the same; I can say all the stories were the same. Any ideas what the next step might be.

  9. bspr3663
    Member
    Posted 2 years ago #

    Not sure if this helps, but I set my campaign as draft and it feed in the title "Listeria outbreak: why more of us didn't get sick" it duplicated 12 times. So I'm guessing it had an issue with the character = :

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags