Skip to content

Instantly share code, notes, and snippets.

@dikiyforester
Last active November 16, 2018 05:02
Show Gist options
  • Save dikiyforester/71edb09fcb2cabed6ceefd67c738a210 to your computer and use it in GitHub Desktop.
Save dikiyforester/71edb09fcb2cabed6ceefd67c738a210 to your computer and use it in GitHub Desktop.
Programmatically Import/export data from the Vantage listings
<?php
function va_custom_import() {
global $vantage;
/**
* 1. Insert & Update listing data.
*
* If you specify listing ID - it will update that listing, otherwise it
* will insert new one.
*
* Use VA_Admin_Importer::import_listing() method for insert/update listing.
*
* You have to prepare formatted data array before use this method.
* See example below.
*/
require_once( APP_FRAMEWORK_DIR . '/admin/importer.php' );
require_once( get_template_directory() . '/includes/admin/class-admin-importer.php' );
if ( ! function_exists( 'wp_generate_attachment_metadata' ) ) {
require_once( ABSPATH . 'wp-admin/includes/image.php' );
require_once( ABSPATH . 'wp-admin/includes/file.php' );
require_once( ABSPATH . 'wp-admin/includes/media.php' );
}
va_csv_importer();
/* @var $importer VA_Admin_Importer */
$importer = appthemes_get_instance( 'VA_Admin_Importer' );
// Register post_id field so we'll able to update items.
$importer->fields['post_id'] = 'ID';
// If empty or zero - it will insert new listing, if it's number - it will
// try to update the listing with this ID.
$item_id = 0;
$sample = array(
'post_id' => $item_id,
'id' => va_generate_id(),
'title' => 'Sprinkles Cupcakes4',
'description' => '<p>We are a Beverly Hills, California-based cupcake bakery chain established in 2005.</p> <p>Sprinkles is considered one of the first cupcake bakeries. We offers cupcakes, ice cream, plus a selection for dogs. See our daily menu with descriptions of each flavor, and online ordering for pick-up or local delivery.</p> <p>Choose from our rotating daily menu of gourmet cupcake flavors like banana, black and white, chai latte, cuban coffee, dark chocolate, red velvet, strawberry, vanilla, and more.</p> <p>https://www.youtube.com/watch?v=dZSHd6trOPo</p>',
VA_LISTING_CATEGORY => 'Dessert',
VA_LISTING_TAG => 'Cupcakes, Bakeries, Desserts',
'author' => '',
'date' => '',
'slug' => '',
'status' => 'publish',
'attachments' => implode( ',', array(
get_template_directory_uri() . '/assets/images/admin/install/sprinkles-cupcakes-cover.jpg',
get_template_directory_uri() . '/assets/images/admin/install/sprinkles-cupcakes-view.jpg',
get_template_directory_uri() . '/assets/images/admin/install/sprinkles-cupcakes-counter.jpg',
get_template_directory_uri() . '/assets/images/admin/install/sprinkles-cupcakes-close-up.jpg',
) ),
'featured_attachment' => get_template_directory_uri() . '/assets/images/admin/install/sprinkles-cupcakes-cover.jpg',
'lat' => '34.069577',
'lng' => '-118.406061',
'address' => '9635 S Santa Monica Blvd, Beverly Hills, CA 90210, USA',
'street_number' => '9635',
'street' => 'South Santa Monica Boulevard',
'city' => 'Beverly Hills',
'state_short' => 'CA',
'state_long' => 'California',
'postal_code' => '90210',
'country_short' => 'US',
'country_long' => 'United States',
'phone' => '(310) 274-8765',
'website' => 'http://sprinkles.com/locations/california/beverly-hills/cupcakes',
'email' => '',
'twitter' => 'sprinkles',
'facebook' => 'sprinkles',
'google-plus' => '+sprinkles',
'instagram' => 'sprinklescupcakes',
'youtube' => 'sprinkles',
'pinterest' => '',
'listing_duration' => 30,
);
// Import listing from the generated sample.
$item_id = $importer->import_listing( $sample );
/**
* 2. Read listing data.
*
* This can be done using Listing Form vodule.
*/
/* @var $form APP_Listing_Form */
$form = $vantage->listing->form;
$data = $form->get_formdata( $item_id );
// Don't forget about geo data. Prior version 4.2.0 everything already
// incuded in $data variable, but later, coordinates will be in the
// separated table.
$geodata = APP_Google_Geocoding::get_post_meta( $item_id );
var_dump( $data, $geodata );
}
add_action( 'init', 'va_custom_import', 99 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment