Skip to content

this filter example, is for wp all export, when exporting for google merchant. It filter for:

  • image_link column is not empty
  • parent product is published (not draft)

where $export_id is the id of your export.

function wp_all_export_csv_rows( $articles, $options, $export_id ) {
    global $wpdb;
    $table = $wpdb->prefix . 'posts';

    if ( $export_id == '3' ) {
        foreach ( $articles as $key => $article ) {
            if ( ! empty( $article['id'] ) ) {
                $row = $wpdb->get_row( "SELECT `post_parent` FROM `" . $table . "` WHERE `ID` = '" . $article['id'] . "' AND `post_type` = 'product_variation'" );
                if ( $row ) {
                    $parent_obj = $wpdb->get_row( "SELECT `post_status` FROM `" . $table . "` WHERE `ID` = '" . $row->post_parent . "' AND `post_type` = 'product'" );
                    if ( $parent_obj ) {
                        $parent_status = $parent_obj->post_status;
                    }
                }
            }
            if ( empty( $article['image_link'] ) || $parent_status != 'publish' ) {
                unset( $articles[ $key ] );
            }
        }
    }
    return $articles; // Return the array of records to export
}
add_filter( 'wp_all_export_csv_rows', 'wp_all_export_csv_rows', 10, 3 );