我正在尝试使用访问存储在用户配置文件中的IDadd_user_meta
以及get_user_meta
函数返回ID,但当我打印出这些值时,会得到这个奇怪的值。我可以看到ID在里面,但我不太明白如何对它进行编码,只显示值,而不显示所有其他内容。[school_id] => Array ( [0] => a:1:{i:0;i:88;} )
How the data is being added
/*
* Create new custom post type post on new user registration
*/
add_action( \'user_register\', \'add_user_to_school_cpt\', 10, 1 );
function add_user_to_school_cpt( $user_id )
{
// Get user info
$user_info = get_userdata( $user_id );
// Create a new post
$school_post = array(
\'post_title\' => get_field(\'name\', \'user_\' . $user_id),
\'post_content\' => $user_info->description,
\'post_type\' => \'school\',
\'post_status\' => \'publish\',
\'post_author\' => $user_id,
);
// Insert the post into the database
$school_id = wp_insert_post( $school_post );
// Add the school ID as a meta data
add_user_meta( $user_id, \'school_id\', [$school_id] );
// Add school custom fields
add_post_meta( $school_id, \'email\', $user_info->user_email );
add_post_meta( $school_id, \'school_telephone\', get_field(\'telephone\', \'user_\' . $user_id) );
add_post_meta( $school_id, \'school_city\', get_field(\'city\', \'user_\' . $user_id) );
add_post_meta( $school_id, \'school_postcode\', get_field(\'postcode\', \'user_\' . $user_id) );
add_post_meta( $school_id, \'school_address\', get_field(\'address\', \'user_\' . $user_id) );
} ```