• Resolved freeriders

    (@freeriders)


    Greetings

    I’m trying to write a class to create post from a csv

    I have no problem to turn my csv content into an array

    my problem is that while it feeds pretty well the database, I have a problem with the user, it keeps on using the details of the first csv line’s author, while other posts have differents author..

    I have tried to unset($_POST[‘user_ID’]) in my for loop.. when I do an echo on the $_POST[‘user_ID’], it shows the correct value, but it look like the wp_write_post(); don’t use it

    any idea?

    at the bottom part of my code

    thank you VERY much in advance

    Steffy

    $postFill is my array from my csv
    
    for($i=0;  $i<count($postFill);$i++)
    		{
    
    		$_POST['edit_date']=	$postFill[$i][0];	
    
    		$_POST['post_title']= $postFill[$i][2];
    		//$_POST['post_title']= $this->cleanInsert($_POST['post_title']);
    		$_POST['post_title']=  wp_specialchars( stripslashes( $_POST['post_title'] ));
    		$_POST['post_title']= funky_javascript_fix( $_POST['post_title'] );
    		$_POST['post_title']= apply_filters( 'default_title', $_POST['post_title'] );
    
    		$_POST['content']=$postFill[$i][3];
    		//$_POST['content']= $this->cleanInsert($_POST['content']);
    		$_POST['content']= wp_specialchars( stripslashes( $_POST['content'] ));
    		$_POST['content']= apply_filters( 'default_content', $_POST['content']);
    
    		$_POST['tags_input'] = $postFill[$i][4];
    
    		$catlist =$postFill[$i][5];
    		$metas[toto_name]=$postFill[$i][1];
    
    		$userName =$postFill[$i][6];
    		$userUrl =$postFill[$i][7];
    		$_POST['user_ID'] = username_exists($userName);
    		if (!isset($_POST['user_ID']))
    			{
    			$userdata = array('user_login' => $userName,'user_pass' => $userPassword, 'user_email' => $userEmail, 'user_url' => $userUrl, 'role' => $userRole);
    			$_POST['user_ID'] = wp_insert_user($userdata);
    			}
    
    		$_POST['jj']= substr($_POST['edit_date'], 0, 2);
    		$_POST['mm']= substr($_POST['edit_date'], 3, 2);
    		$_POST['aa']= substr($_POST['edit_date'], 6, 4);
    		$_POST['hh']= substr($_POST['edit_date'], 11, 2);
    		$_POST['mn']= substr($_POST['edit_date'], 14, 2);
    		$_POST['ss']= substr($_POST['edit_date'], 17, 2);
    
    		$_POST['tags_input'] = explode(",", $_POST['tags_input']);
    
    		$categories = explode(",", $catlist);
    
    		$post_ID = wp_write_post();
    		echo "the user id is ".$_POST['user_ID']." <br />";
    
    		wp_create_categories($categories, $post_ID);
    
    		if (isset($metas))
    			{
    				foreach ($metas as $key => $value)
    				{
    				$_POST['metakeyselect']=$key;
    				$_POST['metavalue']=$value;
    				add_meta( $post_ID );
    				unset($_POST['metakeyselect']);
    				unset($_POST['metavalue']);
    				}
    				unset($value);
    				unset($key);
    			}
    
    		unset($_POST['user_ID']);
    
    		}
Viewing 1 replies (of 1 total)
  • Thread Starter freeriders

    (@freeriders)

    I have sorted it, I have stop to use wp_write_post() and now use wp_insert_post();

    just in case someone face the same problem

Viewing 1 replies (of 1 total)
  • The topic ‘mass feeding with CSV’ is closed to new replies.