WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to insert data into the wp_posts table with the inserted post_id in the 'guid' for a record that doesn't already exist. Below is the closest I've gotten but this doesn't work ($postarr['ID'] is equal to 0).

function filter_handler( $data , $postarr )
    $my_post_id = $postarr['ID'];
    $data['guid'] = get_option('siteurl') .'/?post_type=ai1ec_event&p='.$my_post_id.'&instance_id=';

return $data;

add_filter( 'wp_insert_post_data' , 'filter_handler' , '99', 2 );

$mypost = array(
  'post_author'     => 1,
 'post_content'     => 'Test', 
 'post_status'      => 'publish',
 'post_title'       => $_GET['assignment_name'],
 'post_type'        => 'ai1ec_event',
 'guid'     => ''

$postid = wp_insert_post($mypost);
share|improve this question
up vote 0 down vote accepted

Why would you need that? ID in a database is auto increment - it manages it's value itself. If your target is to set custom guid, you should update the inserted post as soon as it is created via wp_update_post right after your $post_id = wp_inserted_post($mypost); like this:

...Your code above...
$postid = wp_insert_post($mypost);
$data = array(
   'ID' => $postid,
   'guid' => get_option('siteurl') .'/?post_type=ai1ec_event&p='.$postid.'&instance_id='
wp_update_post( $data );
share|improve this answer
Thanks for quick response. I needed this because the solution above didn't work, or at least it didn't when I tried it about an hour ago. I tried it again now and it worked. Thanks again. – amn Feb 2 '13 at 7:17
Also, I can drop the wp_insert_post_data and the filter now. Thanks again. – amn Feb 2 '13 at 7:26

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.