我一直收到以下错误:
PHP Notice: Trying to get property of non-object in /path/converter.php on line 169
我的代码:
$userWP = get_user_by('login' ,$roww['username']); // line 168
$user_id_wp = $userWP->ID; // line 169
echo "UserID WP:".$user_id_wp."<br />"; // line 170
我只是不明白它在寻找什么,或者我做错了什么……有人可以帮忙吗?非常感谢
不确定是否有帮助,但这是我正在处理的代码部分,它是从vbulletin CMS
到Wordpress
的迁移脚本:第154到178行
if ( $row['associatedthreadid'] != 0 ) {
echo $queryx = "SELECT postid,pagetext,username,userid,parentid,dateline FROM post WHERE threadid ='".$row['associatedthreadid']."' ORDER BY parentid,postid ASC";
echo "<br />";
$resultsx = $conn->query($queryx);
$LastCommentID = 0;
$IDPrincipal = "";
$ArrayComment = array();
while ( $roww = $resultsx->fetch_array( MYSQLI_ASSOC ) )
{
echo "UserName CMS:".$roww['username']."<br />";
if( $roww['userid']==1 ){
global $wpdb;
$wpdb->query("UPDATE wp_users SET user_login='".$roww['username']."', user_nicename='".$roww['username']."',display_name='".$roww['username']."' WHERE ID='".$roww['userid']."'");
}
$userWP = get_user_by( 'login',$roww['username'] );
$user_id_wp = $userWP->ID;
echo "UserID WP:".$user_id_wp."<br />";
if( $roww['parentid']==0 ) {
$IDPrincipal = $roww['postid'];
} else {
if( $IDPrincipal==$roww['parentid'] ){
$parentID = 0;
} else {
$parentID = $ArrayComment[$roww['parentid']];
}
答案 0 :(得分:0)
这有点可疑:
if( $roww['userid']==1 ){
global $wpdb;
$wpdb->query("UPDATE wp_users SET user_login='".$roww['username']."', user_nicename='".$roww['username']."',display_name='".$roww['username']."' WHERE ID='".$roww['userid']."'");
}
仅在userid == 1时更新吗?
如果找不到用户,是否有一种分配用户的方法,而不是 跳过条目?
$userWP=get_user_by( 'id', '1' ); //your fallback-user
if(get_user_by( 'login',$roww['username'] )!==false) {
$userWP=get_user_by( 'login',$roww['username'] );
}