Posting in wordpress database as a new post

I have two php websites, I have a form in one custom page which simply inserts data in one database ….all I want is to insert this same data in my second site which is wordpress..to be inserted as a new post.

Ex: in the form i fill title, date, etc in my 1st databse which is a simple php site, now i want is same post gets inserted in my wordpress databse…title as title and data as date.

Read More

Don’t want to use XML etc..as i have both database under same hosting so i have access to both database with single php form…all i want to know is dependent tables for wordpress entry but with an example 🙂

Thanks
Luckyy

Related posts

Leave a Reply

2 comments

  1. You can use WordPress‘s functionality outside of WordPress, just create a subfolder in your site’s root directory, i.e. http://yoursite.com/blog and upload WordPress in your blog sub-folder. For more read this on Codex.

    Then, in order to transform regular PHP pages into ones that utilize WordPress, you need to add either of the following code snippets to the start of each page.

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

    Now look at the wp_insert_post function on Codex to know that how you can insert post into WordPress pragmatically, Also another simplified article if it helps. Now, you know how to use WordPress‘s functions/functionality out side of wordpress and also you know how you can use wp_insert_post, now just setup a PHP page with a form and submit the form using POST methos and the prepare the data for the post to be inserted into the WordPress database (validate inputs) and finally insert using wp_insert_post function. Please read this on codex for more information.

  2. You need to create a PHP script on the WordPress site that accepts a $_POST from the non-Wordpress site’s form.

    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 site 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>