/
var
/
tmp
/
parabrincar
/
export
/
Upload File
HOME
<?php require_once __DIR__ . '/../wp-load.php'; // require_once __DIR__ . '/../wp-admin/includes/taxonomy.php'; $taxonomyList = array( 'product_cat', 'product_tag', 'product_brand' ); $args = array( 'numberposts' => -1, // all 'post_type' => 'product', 'tax_query' => array( array( 'taxonomy' => 'product_brand', 'field' => 'slug', 'terms' => array( 'ataa', 'kiduku', 'pekecars', 'toyfaster', 'tresko', 'xtrm-factory' ), // 'terms' => 'ataa', // 'operator' => 'IN' ) ) ); $productPosts = get_posts($args); $products = array(); foreach($productPosts as $post){ // echo $post->ID . '<br>';; $post->post_meta = get_post_meta($post->ID); if(!empty($post->post_meta['_upsell_ids'])){ unset($post->post_meta['_upsell_ids']); } $post->featured_image = ''; if(!empty($post->post_meta['_thumbnail_id'])){ $image = wp_get_attachment_image_src($post->post_meta['_thumbnail_id'][0], 'full'); if($image) $post->featured_image = $image[0]; unset($post->post_meta['_thumbnail_id']); } $post->gallery_images = array(); if(!empty($post->post_meta['_product_image_gallery'])){ $imageIds = explode(',', $post->post_meta['_product_image_gallery'][0]); foreach($imageIds as $id){ $image = wp_get_attachment_image_src($id, 'full'); if($image){ $post->gallery_images[] = $image[0]; } } unset($post->post_meta['_product_image_gallery']); } $postTerms = array(); foreach($taxonomyList as $taxonomy){ $terms = wp_get_object_terms($post->ID, $taxonomy); $postTerms[ $taxonomy ] = array(); foreach($terms as $term){ $postTerms[ $taxonomy ][] = $term->name; } } $post->post_terms = $postTerms; $products[$post->ID] = $post; } $json = json_encode($products); $file = fopen('export.json', 'w+'); fwrite($file, $json); fclose($file); ?>