Php Can';t将自定义分类添加到CPT

Php Can';t将自定义分类添加到CPT,php,wordpress,taxonomy,custom-taxonomy,Php,Wordpress,Taxonomy,Custom Taxonomy,我已经试了好几天了,就是没法用 我有一个自定义的Post类型,它是一个条目,它保存关于投票人的信息。但是我想根据选民投票的内容对他们进行分类,所以我为此创建了一个自定义分类法,但即使使用静态post ID,它也不会将这个术语添加到post中 <?php //Custom post type for voting function create_entry_post_type() { register_post_type( 'entry', array(

我已经试了好几天了,就是没法用

我有一个自定义的Post类型,它是一个条目,它保存关于投票人的信息。但是我想根据选民投票的内容对他们进行分类,所以我为此创建了一个自定义分类法,但即使使用静态post ID,它也不会将这个术语添加到post中

<?php

//Custom post type for voting
function create_entry_post_type() {
    register_post_type( 'entry',
        array(
            'labels' => array(
               'name' => __( 'Entries' ),
            'singular_name' => __( 'Entry' )
        ),
        'public' => true,
        'has_archive' => true,
        'taxonomies' => array('votes')
    )
);
}
add_action( 'init', 'create_entry_post_type' );

//Adds entry to wordpress
if(isset($_POST['submit'])){
    //Insert data
    $post_id = wp_insert_post(array(
        'post_title' => 'Title',
        'post_content' => 'This is a vote',
        'post_type' => 'entry',

   ));

//Array for values in entry-post type
$values = array(
    'field_5ad8868851c3b' => $_POST['firstname'], //Firstname
    'field_5ad8869d51c3c' => $_POST['lastname'], //Lastname
    'field_5ad886d851c3d' => $_POST['email'], //Email
    'field_5ad886f551c3e' => $_POST['phone'], //Phone
    'field_5ad9d4bfc5860' => $_POST['vote'], //Vote
    'field_5ad9d6f1273ff' => $_POST['coupon_type'] // Coupon Type (sms/email)
);
//Insert for each field
foreach ($values as $key => $value) {
    update_field($key, $value, $post_id);
};

sendToClearOn($_POST["coupon_type"]);
}

function sendToClearOn($coupon_type){
    // TO-DO
}


//
// Testing taxonomies
//
function votes_init() {
    // create a new taxonomy
    register_taxonomy(
        'votes',
        'entry',
        array(
            'label' => __( 'Votes' ),
            'rewrite' => array( 'slug' => 'vote' ),
            'capabilities' => array(
                'assign_terms' => 'edit_guides',
                'edit_terms' => 'publish_guides'
        )
    )
);
}
add_action( 'init', 'votes_init' );

function add_term(){
    wp_set_object_terms( 250, 'Bob', 'vote' );
}
add_action( 'init', 'add_term' );

?>

环顾四周后,我发现我需要给init钩子一个优先级

add_action( 'init', 'function_name', $priority);
经过一点测试,我发现大约50岁是个不错的选择,但你自己试试看