Support » Plugins » Hacks » Special way to assign posts to categories based on posts' tag.

  • I am wondering if someone can suggest a way or a script where posts can be assigned to categories according to the posts’s tags. However I need to do this in bulk for multiple posts.

    For example, if a post has these tags: nice, great and orange I need after having ran the script the post to end up being assigned to categories with names: nice, great and orange. This can assume that each corresponding category already exists.

Viewing 1 replies (of 1 total)
  • Moderator bcworkz


    Query for whichever posts you want to process, possibly all of them. Then loop through all the posts, much like as done on the main page, except in this case you use wp_get_post_tags(). Process the array returned in order to supply arguments for wp_set_post_terms() which will add the categories for each post. You can apply any extra logic to skip certain tags or whatever. Repeat for every post returned from the query.

    In the future, you could capture the proper post status transition to get new and updated posts and use a similar script to add categories based on tags for the post. Thus you would only need to run the bulk script once.

Viewing 1 replies (of 1 total)
  • The topic ‘Special way to assign posts to categories based on posts' tag.’ is closed to new replies.