createcsv.php 2.45 KB
<?php

if (!isset($wp_did_header)) {

    $wp_did_header = true;

    // Load the WordPress library.
    require_once( dirname(__FILE__) . '/wp-load.php' );

    // Set up the WordPress query.
    wp();
}
global $wpdb;
$order_id = 10207;
   $order = new WC_Order($order_id);
    $drinks = 0;
    echo "<pre>";
    print_r($order->get_items());
    foreach ($order->get_items() as $key => $value) {
        if ($value['variation_id'] > 0) {
            print_r($value['item_meta_array'] );
        }
    }
exit();
$arrayData = array();
//For page
$query = "SELECT ID,post_title, post_type FROM $wpdb->posts WHERE `post_status` = 'publish' AND `post_type` = 'page'";
$results = $wpdb->get_results($query);
$i = 1;
$arrayData[0] = array('STT', 'URL', 'Title', 'Description');
if (!empty($results)) {
    foreach ($results as $item) {
        $url = get_permalink($item->ID);
        $titleTag = strtoupper($item->post_title) . " - REIZE";
        $description = "REIZE is the worlds most versatile energy drink, home delivered for as low as 62c per drink. It's sugar free, it's lightweight and it's Most Flavoursome. Caffeine, Taurine and Ginseng combines to give an amazing energy boost. Try it today!";
        $arrayData[$i] = array($i, $url, $titleTag, $description);
        $i++;
    }
}

$query = "SELECT ID,post_title, post_type FROM $wpdb->posts WHERE `post_status` = 'publish' AND `post_type` = 'post'";
$results = $wpdb->get_results($query);
if (!empty($results)) {
    foreach ($results as $item) {
        $url = get_permalink($item->ID);
        $titleTag = $item->post_title . " - REIZE";
        $postShortDes = get_post_meta($item->ID, 'Short Description', true);
        if (!$postShortDes) {
            $description = "REIZE is the worlds most versatile energy drink, home delivered for as low as 62c per drink. It's sugar free, it's lightweight and it's Most Flavoursome. Caffeine, Taurine and Ginseng combines to give an amazing energy boost. Try it today!";
        } else {
            $description = $postShortDes;
        }
        $arrayData[$i] = array($i, $url, $titleTag, $description);
        $i++;
    }
}

//For post

function fgc_create_csv_file($pathFile, $data) {
    if (empty($data))
        return false;
    $file = fopen($pathFile, "w");
    foreach ($data as $line) {
        fputcsv($file, $line); // explode(',', $line)
    }
    fclose($file);
}

fgc_create_csv_file(dirname(__FILE__)."/wp-content/uploads" . DIRECTORY_SEPARATOR . 'seo_reize.csv', $arrayData);
?>