WordPress wp_insert_post没有插入标签

yed*_*del 7 php wordpress

我正在尝试使用此代码插入帖子:

$my_post = array(
                'post_type'    => "essays",
                'post_title'    => 'TEST 3',
                //'post_content'  => $content,
                'post_status'   => 'draft',
                'post_author'   => 1,
                //'post_category' => $cat,
                'tags_input'    => 'TQM,tag',
        );

$post_id = wp_insert_post($my_post);
Run Code Online (Sandbox Code Playgroud)

除了标签之外,Everythings工作正常,它不会插入任何标签.任何的想法?

Adi*_*oui 6

使用wp_set_object_terms()功能:

http://codex.wordpress.org/Function_Reference/wp_set_object_terms

wp_set_object_terms($post_id , $arrayoftags, $name_of_tag_taxonomy, false);
Run Code Online (Sandbox Code Playgroud)

祝好运


Nad*_*adh 4

您的帖子类型是essays. 默认情况下,自定义帖子类型不支持标签。您必须tags为它们添加分类法。

http://codex.wordpress.org/Taxonomies

http://codex.wordpress.org/Function_Reference/register_taxonomy