0

I am looking for a way to assign (add) a category to a list of posts without editing each and every post - even by using bulk edit.

Why? Because doing it manually (even using bulk) will update the published time and I do not want that.

Any idea as to how this can be done? I understand that I need an array of post ID:s, which I have. But how do I do this using my theme's functions file?

1 Answer 1

0

You can set post terms programmatically with wp_set_object_terms(). There's also wp_set_post_terms() which is a wrapper for the first function, but with some extra processing of the parameters in it.

foreach ( $array_of_post_ids as $post_id ) {
    // appends my-category to a post's categories
    wp_set_object_terms( $post_id, 'my-category', 'category', true );
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.