以编程方式将标签添加到WordPress帖子中,而不会覆盖现有标签

我可以在代码中向我的帖子添加标签, 但是它会覆盖现有的标签数组。有谁知道一种将标签添加到预先存在的标签数组中以使所有内容都不会被擦除的方法?

wp_set_object_terms($post_id, 'mytagname', 'post_tag');

WordPress API的这一部分似乎有些笨拙, 但是也许我完全错过了一些东西。任何帮助, 将不胜感激!

事实证明, RTFM是答案。


#1


查看函数的第四个参数-$ append。如果将其设置为true, 则标签将附加到现有标签上;如果为false(默认设置), 则会替换它们。

所以你想这样称呼它:

wp_set_object_terms($post_id, 'mytagname', 'post_tag', true);

来源:

https://www.srcmini02.com/65718.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_40810.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?