Publish to wordpress database as a new post

I have two php sites, I have a form on one custom page that simply inserts data into one database .... all I want to do is paste the same data on my second site, which is wordpress. new post.

Ex: on the form, I fill out the title, date, etc. in my first database, which is a simple php site, now I want the same entry to be inserted into my wordpress databse ... heading as heading and data as date.

I don’t want to use XML, etc., since I have a database under the same hosting, so I have access to a database with one php form ... all I want to know is dependent tables for writing wordpress, but with an example :)

Thanks Luckyy

+4
source share
2 answers

The WordPress function can be used outside of WordPress , just create a subfolder in the root directory of your site, i.e. http://yoursite.com/blog and upload WordPress to the blog subfolder. For more, read this at Codex .

Then, to convert regular PHP pages to those using WordPress, you need to add one of the following code snippets to the top of each page.

 <?php define('WP_USE_THEMES', false); require('./wp-blog-header.php'); // rest of the code using power of wordpress ?> 

Now check out the Codex wp_insert_post function to find out how you can embed a post in WordPress pragmatic way. Also another simplified article if that helps. Now you know how to use WordPress functions / functions outside of WordPress , and also know how you can use wp_insert_post , now just set up a PHP page with a form and submit the form using POST methos and prepare the data for the message that should be inserted into the database WordPress data (check inputs) and finally insert using the wp_insert_post function. Please read this in the code for more information.

+2
source

You need to create a PHP script on a Wordpress site that accepts $ _POST from a form other than Wordpress.

Wordpress site

/ _ static / receiver.php (I always put scripts like this in a folder named _static in the WP root folder):

 <?php require('../wp-load.php'); // Load Wordpress API $data = ( isset( $_POST ) ) ? $_POST : null; // Get POST data, null on empty. $post = array( 'post_title' => $data['post_title'], 'post_content' => $data['post_content'], ); if ( $data && $data['key'] == '1234567890' ) // To Prevent Spam, bogus POSTs, etc. $post_id = wp_insert_post( $post, true ); // Insert Post ?> 

Non-Wordpress Website Form:

 <form method="post" action="http://your-wordpress-site.com/_static/receiver.php"> <input type="text" name="post_title" /> <textarea name="post_content"></textarea> <input type="hidden" name="key" value="1234567890" /> </form> 
+1
source

Source: https://habr.com/ru/post/1488547/


All Articles