Put all articles containing a certain word into a certain category in WordPress

reznev799

Registered Member
Joined
Dec 5, 2022
Messages
66
Reaction score
26
How can i put all articles that are containing a certain word into a certain category in WordPress?
I can't flag and mass edit them via WordPress panel since it crashes. And i can't do it manually 1 by 1 or in lot of 50 articles a time since i've around 2.000.
Any solution? Some db query i can run?
 
Where it says 5 is your category id. The place that says word is the word you are looking for. Don't forget to backup your database!

The following is the SQL code and needs to be executed from phpmyadmin.

INSERT INTO wp_term_relationships (object_id, term_taxonomy_id)
SELECT ID, 5
FROM wp_posts
WHERE post_content LIKE '%word%'
AND post_type = 'post'
AND post_status = 'publish'
AND ID NOT IN (
SELECT object_id
FROM wp_term_relationships
WHERE term_taxonomy_id = 5
)

This SQL code searches for a specific word in your posts and moves all the posts it finds to the category with 5 ids. If you want to search post titles, change post_content to post_title.
 
Where it says 5 is your category id. The place that says word is the word you are looking for. Don't forget to backup your database!

The following is the SQL code and needs to be executed from phpmyadmin.

INSERT INTO wp_term_relationships (object_id, term_taxonomy_id)
SELECT ID, 5
FROM wp_posts
WHERE post_content LIKE '%word%'
AND post_type = 'post'
AND post_status = 'publish'
AND ID NOT IN (
SELECT object_id
FROM wp_term_relationships
WHERE term_taxonomy_id = 5
)

This SQL code searches for a specific word in your posts and moves all the posts it finds to the category with 5 ids. If you want to search post titles, change post_content to post_title.
Exactly this.

Run this directly from your phpmyadmin/mysql prompt.
 
Back
Top