每当我发布一篇文章时,我都试图将一个自定义字段值传递到一个自定义taxamony中。除元价值部分外,一切正常。我只能传递字符串。在法典中,它说wp\\u set\\u post\\u术语采用字符串或数组、标记或类别。但我不能附和一个元值吗?
function add_author_taxonomy( $post_id ) {
global $wpdb;
if(!wp_is_post_revision($post_ID)) {
wp_set_post_terms( $post_id, echo get_post_meta($post_id, \'user_submit_customauthor\', true) , \'author\', true );
}
}
add_action(\'publish_page\', \'add_author_taxonomy\');
add_action(\'publish_post\', \'add_author_taxonomy\');
最合适的回答,由SO网友:jonathan 整理而成
您是否尝试将标记数组构建到变量中,并将其作为参数传递以设置\\u post\\u terms?
function add_author_taxonomy( $post_id ) {
global $wpdb;
if(!wp_is_post_revision($post_ID)) {
$my_tags = get_post_meta($post_id, \'user_submit_customauthor\', true);
wp_set_post_terms( $post_id, $my_tags, \'author\', true );
}
}
add_action(\'publish_page\', \'add_author_taxonomy\');
add_action(\'publish_post\', \'add_author_taxonomy\')
;