Mini Shell
<?php
header("access-control-allow-origin: *");
header('Content-type: application/json');
error_reporting(E_ALL);
ini_set('display_errors', 1);
if(file_exists("wp-load.php"))require( 'wp-load.php' );
else require( '../wp-load.php' );
$title = $_GET['title'];
$json_id = $_GET['json_id'];
$single_image_old = $_GET['single_image_old'];
$price = $_GET['price'];
if (!empty($title) && !empty($json_id) && !empty($price)) {
$input = [
'title' => $title,
'single_image_old' => $single_image_old,
'price' => $price,
'json_id' => $json_id,
];
echo json_encode(['post_id' => WP_HOME.'?p='.auto_product($input)]);
}
function auto_product($input){
global $wpdb;
$data = array(
'post_author' => 1,
'post_content' => '',
'post_content_filtered' => '',
'post_title' => $input['title'],
'post_excerpt' => '',
'post_status' => 'publish',
'post_type' => 'product',
'post_category' => array(),
'comment_status' => 'open',
'ping_status' => 'closed',
'post_password' => '',
'to_ping' => '',
'pinged' => '',
'post_parent' => 0,
'menu_order' => 0,
'guid' => '',
'import_id' => 0,
'context' => '',
);
$product_id = wp_insert_post( $data, $wp_error );
wp_set_object_terms($product_id, 'mmolazi', 'product_type'); // mmolazi for shopify json
add_post_meta($product_id, '_price', $input['price'], true);
add_post_meta($product_id, 'json_id', $input['json_id'], true);
add_post_meta($product_id, 'single_image_old', $input['single_image_old'], true);
// add_post_meta($product_id, 'source', 'https://amazon.com/dp/'.$input['asin'], true);
/** auto make wp_term_relationships */
//$wpdb->insert( $wpdb->term_relationships, array('object_id' => $product_id, 'term_taxonomy_id' => 4, 'term_order' => 0) );
return $product_id;
}