admin管理员组文章数量:1323029
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?
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
Reset to default 0You 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 );
}
本文标签: categoriesAdd Catgory (assign) to Post Programmatically (without editing)
版权声明:本文标题:categories - Add Catgory (assign) to Post Programmatically (without editing) 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742110762a2421244.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论