Blog

How to get posts from a wordpress site to other sites hosted in same server

Posted by : Leo T Abraham on 5 August, 2013

Try the following code:


<?php
    $db_username = '#######';
    $db_password = '#######';
    $db_database = '#######';
    $host =        '#######';

    $blog_url = 'url of the blog/';

    //base folder for the blog.
    //Make SURE there is a slash at the end  
    //connect to the database

    $con = mysql_connect($host, $db_username, $db_password);
    @mysql_select_db($db_database) or die("Unable to select database");
    $query = "Select * FROM wp_posts WHERE post_type='post' AND
    post_status='publish'
    ORDER BY id DESC LIMIT 2";

    $query_result = mysql_query($query);

    while ($row = mysql_fetch_array($query_result)) {
?>
        <div class="blog_cont">
            <b><?php echo $row['post_title'] ?></b>
            <br/>
            <span>
                <?php echo $row['post_content']; ?>
            </span>
        </div>
<?php
   
    }
    @mysql_close($con);
?>

If you are looking for posts from a wordpress site to another wordpress site refer WPMU