WordPress.org

Ready to get started?Download WordPress

Forums

Submit content as a draft? (5 posts)

  1. sackbot14
    Member
    Posted 1 year ago #

    Hello. :)

    Is it possible to submit some content (so a string of some sort) directly to the database as a draft? If so, how can I do so? I am the only one to be doing the submissions, so there is no worry of processing or censoring or any of that sort of precautionary actions to perform.

    I looked at the database tables and found it to be a little... scary to try to do it by myself, so I came here to ask.

  2. bcworkz
    Member
    Posted 1 year ago #

    You could use $wpdb->insert(). Or you could use phpMyAdmin to do it manually. You're better off using wp_insert_post() to be safe, the other methods could easily corrupt things with no indication why. In all cases, the array key or column value of 'post_status' needs to equal 'draft'.

  3. sackbot14
    Member
    Posted 1 year ago #

    Okay, how can I get that function on a file I'm using? It's not in the wordpress directory, the file I am using. Also, the file I am using has another mysql connection, but I can always close that one and open a new one for wordpress as the insertion happens at the end of the script.

  4. bcworkz
    Member
    Posted 1 year ago #

    Oh, that changes things :)
    To use the existing connection, you need to use php's mysql_* functions, which is very roughly the same as using the $wpdb object. As long as you are careful, it will work. To use WP functions, you need to load the WP environment, which will open it's own connection. You normally do this by including wp-load.php on your page. I haven't tried doing this outside of the WP directories, but it shouldn't make any difference.

    DB work outside of WP is not part of my experience, but the wp-load include probably needs to be inside a function to ensure it is not run before the other connection is closed. If it were me, I would go ahead and use the existing connection. I would analyze the insert statement sent from wp_insert_post() to ensure I've got my own statement right. Then test thoroughly that WP sees my insert as a valid draft post before turning my script loose.

  5. sackbot14
    Member
    Posted 1 year ago #

    Got it, thank you so much for the help. :)

Topic Closed

This topic has been closed to new replies.

About this Topic