Does anyone know how to insert a new post into Wordpress using sql?
Using the $wpdb->insert() The basic syntax for inserting data to WordPress database is <? php $wpdb->insert($table_name, $data); ?> . The $table_name is a string that is the name of the database table to insert data into. On the other hand, $data is an array that will be inserted into the database table.
MySQL is also an open source software, just like WordPress and works best with other popular open source software, such as Apache web server, PHP, and Linux operating system. To install WordPress you need a MySQL database. All WordPress hosting providers offer MySQL included in their hosting packages.
You can use the Post object:
// Create post object $my_post = array(); $my_post['post_title'] = 'My post'; $my_post['post_content'] = 'This is my post.'; $my_post['post_status'] = 'publish'; $my_post['post_author'] = 1; $my_post['post_category'] = array(8,39); // Insert the post into the database wp_insert_post( $my_post );
More info found here.
Your question asks how to insert a new post into WordPress using SQL. If you really wanted to do that, taking a look at the "wp" database tables and do a standard INSERT - this wouldn't be hard.
But I'd strongly recommend against doing this - even if you want to create a separate admin dashboard outside of the normal WP-provided one, you should use the core functions/API that they provide. For example, the wp_insert_post function is what you want to use.
I believe you can use/load these functions by including /wp-load.php.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With