• Hello,
    im trying to add trigger to mysql so i stop duplicate posts from wp_automatic.
    i use wp 4.3 and sql 10.0.19-MariaDB and website is https://www.i247.gr
    im trying this:

    CREATE TRIGGER check_dup_titles
    BEFORE INSERT
       ON wpi247_posts
       REFERENCING NEW ROW AS NEWROW
       FOR EACH ROW
       BEGIN ATOMIC
         IF EXISTS (SELECT * FROM wpi247_posts WHERE wpi247_posts.post_title = NEWROW.post_title) THEN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'This title already exists, please enter a different title!'
    END IF;
       END;

    atm, i made a small event which works,

    CREATE EVENTcheck_duplicates; CREATE DEFINER=i247901238@%EVENTcheck_duplicatesON SCHEDULE EVERY 30 SECOND STARTS '2015-08-24 15:00:00' ON COMPLETION NOT PRESERVE ENABLE DO DELETE a.* FROM wpi247_posts AS a INNER JOIN ( SELECT post_title, MIN(id) AS min_id FROM wpi247_posts WHERE post_type = 'post' AND post_status = 'publish' GROUP BY post_title HAVING COUNT(*) > 1 ) AS b ON b.post_title = a.post_title AND b.min_id <> a.id AND a.post_type = 'post' AND a.post_status = 'publish'

    till i fix trigger because wp_automatic posts same posts all the time.

    any help ?

  • The topic ‘prevent duplicate title (posts) with sql trigger’ is closed to new replies.