Php 从wordpress中的自定义用户配置文件字段将数据插入多个表中

Php 从wordpress中的自定义用户配置文件字段将数据插入多个表中,php,sql,database,wordpress,Php,Sql,Database,Wordpress,我在wpadmin中创建了一个自定义配置文件字段,并将其数据保存到usermeta表中。但我需要这些数据也保存在另一个表中“wp\u ppv\u performer\u profile”。此字段是admin中的下拉字段。 我的代码: add_action( 'personal_options_update', 'my_save_extra_profile_fields' ); add_action( 'edit_user_profile_update', 'my_save_extra_profi

我在
wp
admin中创建了一个自定义配置文件字段,并将其数据保存到
usermeta
表中。但我需要这些数据也保存在另一个表中
“wp\u ppv\u performer\u profile”
。此字段是admin中的下拉字段。 我的代码:

add_action( 'personal_options_update', 'my_save_extra_profile_fields' );
add_action( 'edit_user_profile_update', 'my_save_extra_profile_fields' );

function my_save_extra_profile_fields( $user_id ) {
global $wpdb;
    $phs = $_POST['hstatus'];
if ( !current_user_can( 'edit_user', $user_id ) )
    return false;

update_usermeta( $user_id, 'hstatus', $_POST['hstatus'] );


$wpdb->insert( $wpdb->wp_ppv_performer_profile, array("performer_tags" => 
$phs ), array( "performer_id", 5));
}

此代码未给出错误,但未将“hstatus”值保存在表列“performer\u tags”中,该列的performer\u id=5。

这是一个工作示例,请确保表名正确:

add_action('edit_user_profile_update', 'my_save_extra_profile_fields');
function my_save_extra_profile_fields($user_id) {
    if ( current_user_can('edit_user',$user_id) ){
        global $wpdb;
        $status = $_POST['hstatus'];
        update_user_meta($user_id, 'hstatus', $status);

        // change to performer_profile if ppv_ is part of the prefix, only use the table name without prefix.

        $table = $wpdb->prefix . "ppv_performer_profile";

        // performer_tags and performer_id are assumed to be table columns, status is also assumed to be a string here.

        $data = array( 'performer_tags' => $status, 'performer_id' => 5);
        $format = array( '%s', '%d');
        $wpdb->insert( $table, $data, $format ); 
    }
}

下面的代码经过测试,对我来说运行良好。请确保表名和字段名正确无误。如果仍然不工作,那么请调试并让我们知道您发现的确切错误

add_action( 'personal_options_update', 'my_save_extra_profile_fields' );
add_action( 'edit_user_profile_update', 'my_save_extra_profile_fields' );
 function my_save_extra_profile_fields($user_id) {
  if ( current_user_can('edit_user',$user_id) ){
    global $wpdb;
    $status = $_POST['hstatus'];
    update_user_meta($user_id, 'hstatus', $status);    

    $table_name= $wpdb->prefix . "ppv_performer_profile";  // Tablename is wp_ppv_performer_profile , I use $wpdb->prefix which will take defined prefix of wordpress (wp_).


    $insertdata= array( 'performer_tags' => $status, 'performer_id' => 5);       
    $wpdb->insert( $table_name, $insertdata); 
   }
 }

它不起作用了。没有给出任何错误,但仍然不起作用。你能检查你的wp配置并让我知道数据库表中完整的db“prefix”Its wp_uu吗?如果变量正确,并且列存在,那么这个示例应该起作用