Seperate Categories to Diffrent Columns
-
I am using this code to export images to diffrent column. It works for images. I want to print categories and subcategories in different columns by making some improvements. I’m making a mistake somewhere but I couldn’t figure it out. Can you help me?
add_filter('wp_all_export_csv_rows', 'wp_all_export_csv_rows', 10, 3); function wp_all_export_csv_rows( $articles, $options, $export_id ) { if ( $export_id == '40' ) { // change to your export ID foreach( $articles as $key => $article ) { if ( array_key_exists( 'ID', $article ) ) { $i = 1; $product = wc_get_product( $article['ID'] ); $m_category = get_terms( ['taxonomy' => 'product_cat'] ); if ( ! empty( $m_category ) ) { // use $m_category->parent to check if it's a parent category or sub-category. $articles[ $key ]['Category '] = $m_category->name; //category name from category object } if ( ! empty( $product ) ) { $featured_img = wp_get_attachment_url( $product->get_image_id() ); if ( ! empty( $featured_img ) ) { $articles[ $key ]['Image ' . $i] = $featured_img; } $other_imgs = $product->get_gallery_image_ids(); if ( ! empty( $other_imgs ) ) { foreach ( $other_imgs as $id ) { $i++; $img = wp_get_attachment_url( $id ); $articles[ $key ]['Image ' . $i] = $img; } } } } } } var_dump($m_category); return $articles; // Return the array of records to export } add_filter('wp_all_export_csv_rows', 'wp_all_export_csv_rows', 10, 3);
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Seperate Categories to Diffrent Columns’ is closed to new replies.