Forum Replies Created

Viewing 1 replies (of 1 total)
  • Thread Starter hunnx77

    (@hunnx77)

    yes, i tell you earlier if I update product from admin side, category page will be shown.
    there is some problem with the term relationship or something like that. I also work on it but it is still not working.
    Can you send me the exact code for wp_insert_post.
    My code is given below.
    $my_post = array(
    ‘post_title’ => $rt_name,
    ‘post_content’ => $rt_desc,
    ‘post_status’ => ‘publish’,
    ‘post_type’ => ‘product’
    );
    // Insert the post into the database
    $post_id = wp_insert_post( $my_post );

    wp_set_object_terms( $post_id, $tags, ‘product_tag’);

    $category_id = wp_set_object_terms( $post_id, $rt_name, ‘product_cat’);
    //$dish_id = wp_set_object_terms( $post_id, $rt_name, ‘dishes’);
    $cat_id=$category_id[0];
    //$dish_arr_id=$dish_id[0];

    wp_set_post_terms( $post_id, $cat_id, ‘product_cat’);

    $category_link = get_term_link( $cat_id, ‘product_cat’ );
    //$dish = get_term_link( $dish_arr_id, ‘dishes’ );
    //update_post_meta( $post_id, $key, $rt_name );
    update_post_meta( $post_id,’_price’, $rt_price );
    update_post_meta( $post_id,’_regular_price’, $rt_price );
    update_post_meta( $post_id, ‘ingredients’, $rt_ingredients );
    global $wpdb;
    $table_name = ‘wp_term_relationships’;
    $results = $wpdb->get_results(“SELECT term_id FROM wp_term_taxonomy WHERE taxonomy = ‘product_type’LIMIT 0 , 1″);
    //$taxonomy_id=$results->term_id;
    $taxonomyobj=$results[0];
    print_r($taxonomyobj);
    $taxonomy_id=$taxonomyobj->term_id;

    $wpdb->insert(
    $table_name,
    array(
    ‘object_id’ => $post_id,
    ‘term_taxonomy_id’ => $taxonomy_id
    ),
    array(
    ‘%d’,
    ‘%d’
    )
    );
    $wpdb->insert(
    $table_name,
    array(
    ‘object_id’ => $post_id,
    ‘term_taxonomy_id’ => $cat_id
    ),
    array(
    ‘%d’,
    ‘%d’
    )
    );

Viewing 1 replies (of 1 total)