我一直在尝试实现一个自定义端点,将移动应用程序中的数据插入到此数据库。然而,我似乎找不到正确的方法。有些地方使用了#wpdp->插入,而其他地方则使用
$wpdb->获取结果($query),查询将是“插入‘wp\\u woocommerce\\u vendor’。。。。。
没有一个对我有用。我出错了
您的网站出现严重错误。
了解有关在WordPress中调试的更多信息。
如果可能的话,我有没有办法检查回复?例如,如果插入成功
return$data[\'status\']=“数据库添加成功”;
add_action( \'rest_api_init\', \'my_register_route\' );
function my_register_route() {
register_rest_route( \'my-route\', \'my-phrase\', array(
\'methods\' => \'POST\',
\'callback\' => \'custom_phrase\',
)
);
}
function custom_phrase() {
global $wpdb;
$data = array();
$parameters = $request_data->get_params();
$vendor_vendor_id = $parameters[\'vendor_vendor_id\'];
$vendor_product_id = $parameters[\'vendor_product_id\'];
$vendor_product_name = $parameters[\'vendor_product_name\'];
$vendor_product_qty = $parameters[\'vendor_product_qty\'];
$vendor_product_unit_price = $parameters[\'vendor_product_unit_price\'];
$vendor_product_amount = $parameters[\'vendor_product_amount\'];
$vendor_percent = $parameters[\'vendor_percent\'];
$vendor_amount = $parameters[\'vendor_amount\'];
$vendor_order_id = $parameters[\'vendor_order_id\'];
$vendor_order_date = $parameters[\'vendor_order_date\'];
$vendor_send_money_status = $parameters[\'vendor_send_money_status\'];
$vendor_send_money_date = $parameters[\'vendor_send_money_date\'];
$vendor_product_delivared = $parameters[\'vendor_product_delivared\'];
$table = \'wp_woocommerce_vendor\';
$data = array(
\'vendor_vendor_id\' => $vendor_vendor_id,
\'vendor_product_id\' => $vendor_product_id,
\'vendor_product_name\' => $vendor_product_name,
\'vendor_product_qty\' => $vendor_product_qty,
\'vendor_product_unit_price\' => $vendor_product_unit_price,
\'vendor_product_amount\' => $vendor_product_amount,
\'vendor_percent\' => $vendor_percent,
\'vendor_amount\' => $vendor_amount,
\'vendor_order_id\' => $vendor_order_id,
\'vendor_order_date\' => $vendor_order_date,
\'vendor_send_money_status\' => $vendor_send_money_status,
\'vendor_send_money_date\' => $vendor_send_money_date,
\'vendor_product_delivared\' => $vendor_product_delivared
);
$wpdb->insert( $table, $data );
$data[\'status\']=\'Database added Successfully.\';
return rest_ensure_response( \'Hello World! This is my first REST API\' );
}
资料来源:
https://www.tychesoftwares.com/creating-custom-api-endpoints-in-the-wordpress-rest-api/https://developer.wordpress.org/rest-api/extending-the-rest-api/adding-custom-endpoints/