admin管理员组文章数量:1320661
My code is not working, it does not add the taxonomy
add_action('init', 'post_test', 10);
function post_test() {
$empty = get_page_by_title('Produto teste', OBJECT, 'produtos');
if(empty($empty)) {
$insert_post = array(
'post_status' => 'publish',
'post_type' => 'produtos',
'post_title' => 'Produto teste',
);
$post_id = wp_insert_post($insert_post);
if ($post_id) {
wp_set_post_terms($post_id, array('metais'), 'categoria-produtos'); // tag metais id is 108
}
add_post_meta($post_id, 'fornecedores', '5948'); // id do fornecedor
add_post_meta($post_id, '_fornecedores', 'field_52377232eb265');
}
}
why not work?
My code is not working, it does not add the taxonomy
add_action('init', 'post_test', 10);
function post_test() {
$empty = get_page_by_title('Produto teste', OBJECT, 'produtos');
if(empty($empty)) {
$insert_post = array(
'post_status' => 'publish',
'post_type' => 'produtos',
'post_title' => 'Produto teste',
);
$post_id = wp_insert_post($insert_post);
if ($post_id) {
wp_set_post_terms($post_id, array('metais'), 'categoria-produtos'); // tag metais id is 108
}
add_post_meta($post_id, 'fornecedores', '5948'); // id do fornecedor
add_post_meta($post_id, '_fornecedores', 'field_52377232eb265');
}
}
why not work?
Share Improve this question asked Sep 17, 2013 at 19:00 RaankRaank 3341 gold badge4 silver badges10 bronze badges1 Answer
Reset to default 22As stated in the wp_set_post_terms
Comment:
This function will only work on the native post type. For a taxonomy on a custom post type use wp_set_object_terms()
wp_set_object_terms
本文标签: Wp set post terms not work
版权声明:本文标题:Wp set post terms not work 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742064037a2418724.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论