Вот код который я запускаю в page.php $a1 = array( 'user_id' => 2, 'meta_key' => 'first_name', 'meta_value' => 'eee' ); $a2 = array( '%d', '%s', '%s' ); if (get_current_user_id() == 1) { global $wpdb; $wpdb->insert( $wpdb->usermeta, $a1, $a2); $email = $wpdb->get_var("SELECT user_email FROM $wpdb->users WHERE user_login = 'wpadm' "); echo $email; } Последние две строки работают. EMail выводится. Т.е. $wpdb работает. Но insert не происходит!!! Уже голову сломал! Проверка error_reporting(E_ALL); ini_set('display_errors', 1); ничего не выводит
Не получается не массив Warning: Invalid argument supplied for foreach() in ....../docs/wp-includes/wp-db.php on line 2296 Вот описание и сама функция Insert из wp-db.php: ** * Insert a row into a table. * * wpdb::insert( 'table', array( 'column' => 'foo', 'field' => 'bar' ) ) * wpdb::insert( 'table', array( 'column' => 'foo', 'field' => 1337 ), array( '%s', '%d' ) ) * * @since 2.5.0 * @see wpdb:repare() * @see wpdb::$field_types * @see wp_set_wpdb_vars() * * @param string $table Table name * @param array $data Data to insert (in column => value pairs). * Both $data columns and $data values should be "raw" (neither should be SQL escaped). * Sending a null value will cause the column to be set to NULL - the corresponding format is ignored in this case. * @param array|string $format Optional. An array of formats to be mapped to each of the value in $data. * If string, that format will be used for all of the values in $data. * A format is one of '%d', '%f', '%s' (integer, float, string). * If omitted, all values in $data will be treated as strings unless otherwise specified in wpdb::$field_types. * @return int|false The number of rows inserted, or false on error. */ public function insert( $table, $data, $format = null ) { return $this->_insert_replace_helper( $table, $data, $format, 'INSERT' ); }
$wpdb->query('INSERT INTO `cms_wp_usermeta`(`user_id`, `meta_key`, `meta_value`) VALUES (44,55,66)'); не выполняется! сам запрос непосредственно в phpMyAdmin выполняется. Но через метод query класса wpdb НЕТ!!! Что за хрень??? Пробовал по разному $wpdb->query("INSERT INTO $wpdb->usermeta ('user_id', 'meta_key', 'eta_value') VALUES (44,55,66)"); Это же работает: $email = $wpdb->get_var("SELECT user_email FROM $wpdb->users WHERE user_login = 'wpadm' ");