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 'm using wordpress 3.0.5 I have to use sql for create post, here is my SQL query:

$req = $bdd->prepare('INSERT INTO wp_posts (post_title,post_content,post_name,post_date,post_date_gmt,post_modified,post_modified_gmt,post_author,post_status,post_type)
                      VALUES (:post_title, :content, :post_name, now(), now(), now(), now(), 1 ,\'publish\', :post_type)');

Everything is fine, my post is created as I want, BUT when I edit my post in admin, for exemple adding a new term, post_status is no more "Publish", but "Scheduled" an my only solution is to ('UPDATE wp_posts SET post_status = \'publish\' WHERE id = :id_post')

When I creat a post directly in admin, everything is fine even if I edit my post.

I think I missed up the scheduled time !

Can you help me ? Thank you for your interest.

share|improve this question

Why are you using direct SQL query instead of wp_insert_post()?

I see that you seem to be using non-standard database object. It is hard to guess what goes wrong if you are doing something considerably different from native mechanics.

share|improve this answer
Thank for your answer, but I was wondering, what if I can't/don't want to use my script in a wordpress install ? – user3136 Feb 14 '11 at 11:30
@Elium2009 if you take a look at the source of wp_insert_post() - it is quite extensive function, not simply stuffing values into database. I don't think it is good/secure idea to fill WP database directly. In my opinion there are better ways to handle this, like loading WP core in external code or writing custom import routine as WP plugin. – Rarst Feb 14 '11 at 11:39
"Loading WP core in external code" Love that way ! Thank you ! – user3136 Feb 14 '11 at 11:58

Your Answer


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