2012-04-30 46 views
0

我嘗試添加未發佈的新節點。節點保存狀態

我設置了狀態= 0;

但是當檢查這個節點時,status = 1;

此代碼。

$node = new StdClass(); 
       $node->type = 'article'; //giving it type 
       $node->title = $article->headline; //gives title 
       $node->body = $article->body; //gives body 

       $node->field_abstract[0]['value'] = $article->summary; 
       $node->field_is_syndigate[0]['value'] = 1; 
       $node->field_syndigate_first_time[0]['value'] = 1; 

       $node->language = $language->language; //'en' or 'ar' 
       $node->comment = 2; //read&write comment 

       //$node->created = $article->parsed_at; 
       $node->created = ''; 
       $node->changed = $node->created; 
       $node->status = 0; 
       $node->promote = 0; 
       $node->sticky = 0; 
       $node->format = 4; // Editor Filtered HTML 
       $node->uid = $user->uid; 

       //$node->field_attribution[0]['value'] = $article->copyright; // attribution 
       $attribution = ''; 
       if($article->logo_path){ 
        $attribution = '<img src="http://pub.syndigate.info/logos/small/'.$article->title_id.'.png" title="'.$article->title_name.'" border="0" />'; 
        if($article->website){ 
         $attribution = '<a href="'.$article->website.'" title="'.$article->title_name.'" target="_blank">'.$attribution.'</a>'; 
        } 
        $attribution .= ' '; 

       } 
       $attribution .= $article->copyright; 
       $node->field_attribution[0]['value'] = $attribution; // attribution 
       $node->field_source[0]['value'] = $article->title_id; // source 
       node_save($node); 

如何將節點保存爲未發佈。

回答

2

當以編程方式創建一個節點,你需要設置

$node->is_new = TRUE; 

如果您在$node->created設置爲空值,我建議擺脫這條線從你的腳本,node_save()會照顧的。同爲$node->changed您給相同的值,從您的腳本只是刪除這條線以及

希望這有助於