admin管理员组文章数量:1326315
I am adding tags during wp_insert_post using wp_set_post_terms. But I have no clue how to add a tag description with my code. I have not found anything out there.
I am adding tags during wp_insert_post using wp_set_post_terms. But I have no clue how to add a tag description with my code. I have not found anything out there.
Share Improve this question asked Aug 9, 2020 at 8:55 Robin AlexanderRobin Alexander 1538 bronze badges1 Answer
Reset to default 2You can't use wp_set_post_terms()
to set the term description, but you can use wp_insert_term()
to create the term and set the description (plus other details), and then pass the term ID to wp_set_post_terms()
.
Working example for one term:
$taxonomy = 'category';
$term_name = 'Foo Bar';
// First we create the term (if it doesn't already exist).
if ( ! $term = term_exists( $term_name, $taxonomy ) ) {
$term = wp_insert_term( $term_name, $taxonomy, array(
'description' => 'Test category',
) );
}
// Now assign the term to the post (here the post ID is 1).
if ( $term && ! is_wp_error( $term ) ) {
wp_set_post_terms( 1, $term['term_id'], $taxonomy );
}
本文标签: termsAdd Taxonomy Description with wpsetpostterms
版权声明:本文标题:terms - Add Taxonomy Description with wp_set_post_terms 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742202711a2432255.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论