CopyPastor

Detecting plagiarism made easy.

Score: 0.80841064453125; Reported for: Open both answers

Possible Plagiarism

Plagiarized on 2017-08-17
by Vishal Panchal

Original Post

Original - Posted on 2013-12-26
by Gman



            
Present in both answers; Present only in the new answer; Present only in the old answer;

I hope this will help you.
solution:
global $post; $prod_terms = get_the_terms( $post->ID, 'product_cat' ); foreach ($prod_terms as $prod_term) { // gets product cat id $product_cat_id = $prod_term->term_id; // gets an array of all parent category levels $product_parent_categories_all_hierachy = get_ancestors( $product_cat_id, 'product_cat' ); // This cuts the array and extracts the last set in the array $last_parent_cat = array_slice($product_parent_categories_all_hierachy, -1, 1, true); foreach($last_parent_cat as $last_parent_cat_value){ // $last_parent_cat_value is the id of the most top level category, can be use whichever one like echo '<strong>' . $last_parent_cat_value . '</strong>'; } }
After a lot of research I figured a way to solve this. I hope this will help someone.
solution:
global $post; $prod_terms = get_the_terms( $post->ID, 'product_cat' ); foreach ($prod_terms as $prod_term) { // gets product cat id $product_cat_id = $prod_term->term_id; // gets an array of all parent category levels $product_parent_categories_all_hierachy = get_ancestors( $product_cat_id, 'product_cat' ); // This cuts the array and extracts the last set in the array $last_parent_cat = array_slice($product_parent_categories_all_hierachy, -1, 1, true); foreach($last_parent_cat as $last_parent_cat_value){ // $last_parent_cat_value is the id of the most top level category, can be use whichever one like echo '<strong>' . $last_parent_cat_value . '</strong>'; } }

        
Present in both answers; Present only in the new answer; Present only in the old answer;