• Resolved bek2bek

    (@bek2bek)


    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)
  • Plugin Author WP All Import

    (@wpallimport)

    Hey @bek2bek,

    This is a pretty advanced snippet, so we wouldn’t be able to help modify/troubleshoot it, but we can leave this thread open for a while in case anyone comes across it and is able to help out.

    Thread Starter bek2bek

    (@bek2bek)

    I gave up. But i got question when i use strip_tags or preg_replace to remove tags from content column it breaks exported csv file. When i use it exports like one column

    Plugin Author WP All Import

    (@wpallimport)

    Hi @bek2bek,

    But i got question when i use strip_tags or preg_replace to remove tags from content column it breaks exported csv file. When i use it exports like one column

    I’d have to see this in action to understand what’s going wrong. Please replicate it on a sandbox site at https://www.wpallimport.com/debug/, then open a support request with the sandbox site URL, a brief description of the issue, and a link to this thread here: https://www.wpallimport.com/support/.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Seperate Categories to Diffrent Columns’ is closed to new replies.