hunnx77
Forum Replies Created
-
Forum: Fixing WordPress
In reply to: Products are not showing on product-category Pageyes, 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(“SELECTterm_id
FROMwp_term_taxonomy
WHEREtaxonomy
= ‘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’
)
);