Wordpress Import data into post table and postmeta table

I’m in the midst of writing my first plugin and I’ve hit a bit of bump.

I’m pulling data from an RSS, importing it into a temporary table, I’m querying that table and importing certain qualifying records into the wp_posts table. I have a few extra bits of data that I thought I would store into a custom field. I have two custom fields to be exact.

The way i am doing the insert query is using $wpdb. I’ve built an array of values based off of a previous query. This allow for one insert statement, but I might need to change this part in order to get the $wpdb->last_inserted_id; I want to make sure before i start rewriting things that I should break my insert statement into individual insert statement and then use add_post_meta after each insert statement.

Ideally, I’d like to have one insert statement and then somehow update both posts and postmeta tables at the same time. IS that possible?

Here is the query that I have write now…this query sits just outside of my foreach loop which builds the array of values called $array_imports.



foreach ( $myrows as $myrow )	{
 // do some stuff
}

$impsql = $wpdb->prepare (
	"INSERT INTO $wpdb->posts
	(`post_author`, `post_date`, `post_date_gmt`, `post_content`, `post_title`, `post_excerpt`, `post_status`, `comment_status`, `ping_status`, `post_password`, `post_name`, `to_ping`, `pinged`, `post_type`)
	VALUES ". implode(',', $array_imports)
);
$wpdb->query($impsql);


I’ve outputted $wpdb->last_inserted_id and its only saving the first one…Probably because the way i am doing this and it being one insert statement. The more I think about it the more i think i need to make individual insert statement so the last insert id is available to me. :rolleyes: