Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inserting a post in Wordpress using MySql

Tags:

Does anyone know how to insert a new post into Wordpress using sql?

like image 927
Uffo Avatar asked Nov 03 '09 23:11

Uffo


People also ask

How do I insert data into MySQL database in WordPress?

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.

Can you use MySQL with WordPress?

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.


2 Answers

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.

like image 132
Chuck Conway Avatar answered Sep 30 '22 06:09

Chuck Conway


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.

like image 35
philfreo Avatar answered Sep 30 '22 05:09

philfreo