I am adding location categories to posts based on keywords in title (with regex), I got it working once, so code is fine the first time, but now get SQL Error (1062) Duplicate entry '4419-268'
so I assume its because some fields already are filled because it worked once...what is the correct code for updating categories even when some might already have same one? my regex catches some already with that category
here is my current code
INSERT INTO wp_term_relationships (term_taxonomy_id, object_id) SELECT '268', ID FROM `wp_posts` WHERE (post_title REGEXP '€|E\\.U\\.|Euro|Europe|Germany|Deutschland|Berlin|Munich|München' OR post_content REGEXP '€|E\\.U\\.|Euro|Europe|Germany|Deutschland|Berlin|Munich|München') AND post_type = 'post'
cheers
Ben
I am adding location categories to posts based on keywords in title (with regex), I got it working once, so code is fine the first time, but now get SQL Error (1062) Duplicate entry '4419-268'
so I assume its because some fields already are filled because it worked once...what is the correct code for updating categories even when some might already have same one? my regex catches some already with that category
here is my current code
INSERT INTO wp_term_relationships (term_taxonomy_id, object_id) SELECT '268', ID FROM `wp_posts` WHERE (post_title REGEXP '€|E\\.U\\.|Euro|Europe|Germany|Deutschland|Berlin|Munich|München' OR post_content REGEXP '€|E\\.U\\.|Euro|Europe|Germany|Deutschland|Berlin|Munich|München') AND post_type = 'post'
cheers
Ben
Share Improve this question edited Jun 9, 2019 at 2:46 Benedict Harris asked Jun 8, 2019 at 10:47 Benedict HarrisBenedict Harris 1213 bronze badges1 Answer
Reset to default 0figured it out. I spent literally days trying different code and the answer was under my nose. Lack of sleep!
replace "INSERT" with "REPLACE"
any tips for removing a category?