Adding one default category and one from user by select option???
-
Adding one default category and one from user by select option??? – I want to add 2 categories, one is user selected from the select option and one is already selected by default. for example my by default categories ID is 20.
if(count($errors) == 0) { $allowed_tags = wp_kses_allowed_html( 'post' ); $title = esc_attr($_POST['coupon_title']); $description = wp_kses($_POST['coupon_description'], $allowed_tags); $cat = (int)$_POST['coupon_cat']; $discount = esc_attr($_POST['coupon_discount']); $code = esc_attr($_POST['coupon_code']); $url = esc_url($_POST['coupon_url']); $date = $_POST['coupon_date']; if(is_user_logged_in() ) { $current_user = wp_get_current_user(); $user_id = $current_user->ID; } else { $user_id = 1; } $post = array( 'comment_status' => 'close', /* added by AB, open */ 'ping_status' => 'close', /* added by AB, open */ 'post_author' => $user_id, 'post_content' => $description, 'post_status' => 'publish', /* added by AB, pending */ 'post_title' => $title, 'post_type' => 'coupons', ); $post_id = wp_insert_post($post); if($post_id == 0) { $errors[] = __("The listing couldn't be added to the database, try again.", "Teo"); } else { $cat = (array)$cat; wp_set_post_terms($post_id, $cat, 'category'); //setting the correct category
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Adding one default category and one from user by select option???’ is closed to new replies.