Question

I am working on a script to convert all posts in a given category to use a postmeta flag instead (testing of MySQL has shown me that on a site as large as mine this will lead to a meaningful decrease in query time).

When converting posts I want to just fetch all posts in the category, add the postmeta then remove the category, which will let me just reload that function until there are no more posts in the category.

I can't find a good function for removing a term from a post though. I want to give it the post id and the term taxonomy+ID and have it handled for me.

I am also interested in plugins that can do the conversion for me if anyone knows of one. I couldn't find any that did cat->postmeta, unlike the opposite which can be handled by Scribu's plugin.

Was it helpful?

Solution

Hmmm, can't remember or find fitting function either.

There is wp_set_object_terms() that is used in multiple wrappers like wp_set_post_categories(). It can overwrite categories for a post.

So you can get post categories, check for unwanted one and write it back excluding unwanted in that case.

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top