1

I have a whole bunch of posts that I need to add a category to (too many to do via Bulk Actions). They all follow a predictable/consistent post title naming structure that could be matched via regex.

My pseudo-code is:

IF post title matches regex "X"
THEN apply Category "Y" (ie to the matching posts)

I was thinking that this is probably something I can run one-time in a custom PHP script?

I found wp_set_post_categories (link), but not sure how to use it to assign a category to all posts based on the title text pattern... It seems to be made for updating individual posts?

Thanks

  • Since this sounds like a one-time update, have you considered using a plugin to export your post data into a CSV, make the necessary changes in Google Docs or Microsoft Excel, and then importing the updated categories back in? – MarkPraschan Nov 20 '19 at 20:16
  • No I never thought of that! I didn't realize you could export post data to a CSV. There are a huge number of posts (>100,000), which I why I need a method of doing this... Do you have a guide or anything you could point to, and/or add it as an answer? – Drewdavid Nov 21 '19 at 0:04
  • wp_set_object_terms may also be helpful here? – Drewdavid Nov 21 '19 at 5:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.