Mass “create post” for 1000′s of posts

Hello all

We have roughly 18,000 listings that were imported as custom post types. We are using formidable to allow users to create new posts from the front end (this works great – perfect).

Our problem lies in finding a way to create formidable entries (including proper author) for the imported listings so that our current userbase can edit these listings.

I know we can individually “create an entry” if we edit each of the 18000 entries one after another, however I was wondering if there was a way to run a function that loop over all posts in a given post type and create a formidable entry that our users could then edit these legacy imported posts from the front end like they would new ones.

This is a one time thing that has to be done.. but am unsure of the best way to accomplish this. Any suggestions would be greatly appreciated.. we are looking at a enormous undertaking if we hae to do this one by one.

Thank in advance

 

Here's a related post:
http://formidablepro.com/help-desk/display-existing-posts/

This is untested for allowing the post author to edit. I'm not sure if that will work or not. I'd suggest starting with only a few entries at once for testing rather than going through all of them.

Ok.. great. I think i get the idea there

If I may be a bit of an imposition, can you confirm i understand this correctly ?

In the code below taken from the post you suggest...

We select all the postIDs that are already in the formidable entries table- assign to $frm_posts
We create a where clause with list of id's to ignore - assign to $where
We execute a query on WPDB returning post ID, author using $where clause (ignore post id's in formidable entries table) - assign to $post
We loop over the $post array inserting ID, user_id and form_id (the form id of the form that users will use to edit these posts )
Then we disable the action so it doesnt run again - voila

Is is true that we ONLY have to insert Post ID, User ID and Form ID in the entries table?.. or do I need to insert all the post info, postmeta info and post type as well?

I think you mentioned in the past that formidable doesnt actually store post/postmeta/post type in formidable forms rather pulls required data from post/postmeta table based on Post ID as needed .. is this correct? In which case the code makes perfect sense.
add_action('admin_head', 'add_posts_to_frm');
function add_posts_to_frm(){
global $wpdb, $frmdb;
$frm_posts = $wpdb->get_col("SELECT post_id from $frmdb->entries WHERE post_id > 0");
$where = '';
if($frm_posts)
$where = 'WHERE ID not in ('. implode(',', $frm_posts) .')';
$posts = $wpdb->get_results("SELECT ID, post_author FROM $wpdb->posts $where LIMIT 100");
//only import 100 at a time. Each page refresh will import the next 100
foreach($posts as $post){
$wpdb->insert($frmdb->entries, array('post_id' => $post->ID, 'user_id' => $post->post_author, 'form_id' => 5)); //change 5 to the ID of your post form
}
}

Yes to all. And the info from the post is not duplicated, so the rest of the post data is unnecessary.

Hey Stephanie..

One more question, what page actually triggers this function?.. I have added the function to my functions.php file.. but can't seem to get it to fire..

Thanks for just a little more guidance

;)

 

That uses "admin_head", so anywhere in the admin.

hmm.. anywhere in /wp-admin  or specifically /wp-admin/admin.php?page=formidable ? I gather this will simply automatically execute everytime I reload the page .. so I need to go to the formidable entries table for the form recieveing the data and see the entries populate. right?

I must have something wrong in the code. Not seeing any entries get written.. hmm

Thanks

 

You can debug by turning on debug mode to see any error messages. Turn on WP_DEBUG in your wp-config.php.

Topic closed.