wp_insert_user不会返回用户的ID

时间:2018-03-27 21:39:51

标签: php wordpress woocommerce

我有一个市场网站,用户添加产品然后注册。添加用户并添加产品但是在使用wp_insert_user之后我无法获得附加到产品的用户ID。这就是我所拥有的。

在我的page-list.php

   if(isset($_POST['user_signup']) == '1') {

    $user_login = $_POST['email_seller'];
    $pas1 = $_POST['pass_seller'];
    $user_email = $_POST['email_seller'];
    $seller_name = $_POST['name_seller'];
    $userdata = array(
        'user_login'  =>  $user_login,
        'user_email' =>  $user_email,
        'user_pass'   =>  $pas1,
        'role' => 'seller', 
         'first_name' => $user_email,
            'last_name' => $user_email,

    );
  $user_id = wp_insert_user( $userdata ) ;

以及我在functions.php中的代码

add_action( 'user_register', 'create_new_user_posts', 10, 1 );

function create_new_user_posts($user_id){
        if (!$user_id>0)
                return;



                $post_title = $_POST['post_title'];
                $post_cat = $_POST['cat'];
                $term_id = get_term( $post_cat, 'product_cat' );
                $post_category = $term_id->slug; 
                $post_cat_two = $_POST['cat_two'];


                $new_post = array(
                      'ID' => '',
                      'post_author' => $user_id, 
                      'post_content' => $post_content, 
                      'post_title' => wp_strip_all_tags($post_title),
                      'post_status' => 'publish',
                      'post_type' => 'product',
                      'post_excerpt'=> $post_excerpt
                    );

                $post_id = wp_insert_post($new_post);

                wp_set_object_terms( $post_id, $user_id, 'soldby', false );



}

0 个答案:

没有答案