Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Wordpress函数wp_set_object_term未设置术语_Php_Wordpress_Woocommerce_Custom Post Type - Fatal编程技术网

Php Wordpress函数wp_set_object_term未设置术语

Php Wordpress函数wp_set_object_term未设置术语,php,wordpress,woocommerce,custom-post-type,Php,Wordpress,Woocommerce,Custom Post Type,我正试图在wordpress中插入一篇新文章。这篇文章是woocommerce的产品,但我正试图根据需要设置条款。我确实得到了很好的返回值,但它没有插入到数据库中 我的代码: // Set the page ID so that we know the page was created successfully $my_post = array( 'post_title' => $_POST['post_title'], 'p

我正试图在wordpress中插入一篇新文章。这篇文章是woocommerce的产品,但我正试图根据需要设置条款。我确实得到了很好的返回值,但它没有插入到数据库中

我的代码:

    // Set the page ID so that we know the page was created successfully
    $my_post = array(
        'post_title'        =>  $_POST['post_title'],
        'post_author'       =>  $_POST['current_user'],
        'post_content'      =>  '',
        'comment_status'    =>  'closed',
        'ping_status'       =>  'closed',
        'post_status'       =>  'pending',
        'post_type'         =>  'product'
    );
    $my_post_id = wp_insert_post($my_post, true);

    var_dump($my_post_id);

    if($my_post_id == 0) {
        //Obviously something went wrong
    } else {
        add_post_meta($my_post_id, '_auction_start_price', $_POST['prijs_start']);
        add_post_meta($my_post_id, '_auction_type', 'reverse');
        add_post_meta($my_post_id, '_auction_item_condition', 'new');
        add_post_meta($my_post_id, '_auction_dates_from', $_POST['start_auction']);
        add_post_meta($my_post_id, '_auction_dates_to', $_POST['end_auction']);
        add_post_meta($my_post_id, '_auction_bid_increment', '25');
        $tvar = wp_set_object_terms($new_post_id, 'auction' ,'product_type');
        $tvar2 = wp_set_object_terms($new_post_id, intval($_POST['cat_id']), 'product_cat');
        if(is_wp_error( $tvar )){
            echo 'ERROR';
        }
        var_dump($tvar);
        var_dump($tvar2);
    }
$tvar和$tvar2返回的内容:

int(908) //Post ID
array(1) { [0]=> string(2) "48" } //The Auction TermID
array(1) { [0]=> string(2) "57" } //The Category TermID

仍然没有在数据库中设置任何idea?

我没有注意到您的代码中有任何对$new\u post\u id的引用,因此以下内容是不正确的

$tvar = wp_set_object_terms($new_post_id, 'auction' ,'product_type');
$tvar2 = wp_set_object_terms($new_post_id, intval($_POST['cat_id']), 'product_cat');
应该是

$tvar = wp_set_object_terms($my_post_id, 'auction' ,'product_type');
$tvar2 = wp_set_object_terms($my_post_id, intval($_POST['cat_id']), 'product_cat');

哎呀,该死的,你的权利,看了大约100遍,没有找到:谢谢我知道并理解这种感觉:很高兴我能帮上忙。