Php 使用WP ALL IMPORT时如何将数据插入到数据库上的特定表中
首先,对不起,我的英语不是最好的。我希望你能帮助我 我正在开发一个使用RnB-WooCommerce预订和租赁插件的Wordpress网站。插件工作正常。当我尝试从CSV文件使用WP ALL导入创建我的产品时,问题就出现了 这个插件为产品使用了2种post类型Php 使用WP ALL IMPORT时如何将数据插入到数据库上的特定表中,php,mysql,wordpress,wpallimport,Php,Mysql,Wordpress,Wpallimport,首先,对不起,我的英语不是最好的。我希望你能帮助我 我正在开发一个使用RnB-WooCommerce预订和租赁插件的Wordpress网站。插件工作正常。当我尝试从CSV文件使用WP ALL导入创建我的产品时,问题就出现了 这个插件为产品使用了2种post类型 产品:与woocommerce相同,但具有连接到“库存”CPT的新元数据 存货:新的邮政类型,有每天的价格范围、数量等(租赁产品的所有数据) 我可以插入进行2次导入所需的所有数据。一个用于产品,一个用于库存。问题在于,这个插件在数据库中有
function id_returner($title = null) {
if ( !empty( $title ) ) {
$ids = get_page_by_title( $title, OBJECT, 'inventory' );
$id = $ids->ID;
return $id;
}
}
然后,我尝试在functions.php上添加这段代码,以便在Wp All Import创建/保存帖子时钩住此操作
add_action('pmxi_saved_post', 'post_saved', 10, 1);
function post_saved($id) {
$inventario = get_post_meta($id, 'id_inventario', true);
global $wpdb;
$table = $wpdb->prefix.'wpmp_rnb_inventory_product';
$data = array('column1' => $inventario, 'column2' => $id);
$format = array('%s','%d');
$wpdb->insert($table,$data,$format);
$my_id = $wpdb->insert_id;
}
但这根本不起作用。我没有收到任何错误消息,但是在导入之后,表是空的
我希望你能帮助我!。感谢您抽出时间您可以将
\u redq\u product\u inventory
自定义字段元素从“可用数据”部分拖放到导出项目中。它应该添加库存ID
自定义导入时,请创建一个新的自定义字段,使用\u redq\u product\u inventory
作为名称,使用{\u redq\u product\u inventory[1]}
作为值
以下是将产品和库存导入表的函数:
add_action('pmxi_saved_post', 'post_saved', 10, 1);
function post_saved($product_id) {
$inventories = get_post_meta($product_id,'_redq_product_inventory',true);
global $wpdb;
$table = $wpdb->prefix.'rnb_inventory_product';
foreach($inventories as $inventory) {
$data = array('inventory' => $inventory, 'product' => $product_id);
$format = array('%d','%d');
$wpdb->insert($table,$data,$format);
}
}
如果使用WP All import删除并重新导入库存,其新ID将与产品中的ID不匹配。为了避免这种情况,您可以使用工具>>导出和工具>>导入进行库存发布
add_action('pmxi_saved_post', 'post_saved', 10, 1);
function post_saved($product_id) {
$inventories = get_post_meta($product_id,'_redq_product_inventory',true);
global $wpdb;
$table = $wpdb->prefix.'rnb_inventory_product';
foreach($inventories as $inventory) {
$data = array('inventory' => $inventory, 'product' => $product_id);
$format = array('%d','%d');
$wpdb->insert($table,$data,$format);
}
}