Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am just wondering if it is possible to show just the page content of another wordpress database on wordpress pages with the same pageID within the content loop in my page template. To be more specific, I want to show the content of one separate wordpress database in another wordpress installation without duplicating it. Its just the page content I want to get, so no articles needed. The structure and page ids of the two wordpress installations are identical.

I want to adress the database using $wpdb but have no idea how to deal with that problem and if its possible to solve it at all?


edit: They are not the same domain. And thank you for commenting, kaiser! I want to have two separate, identical wordpress installations, sharing the page content of one single database, but keeping their individual local settings (local database), themes and styles. As I said, the structure of the sites (navigation, page IDs) is identical. In this case I use Wordpress more like a CMS then a Blog System, and the media library is delivered via CDN, so media-content won't be a problem in shared content.

My first idea was to get $wpdb in my page template to get the content of the external database. But this would mean to adress the page content by page ID, wouldn't it?


edit2: Here's what I tried today:

    <?php
    $wpdbtest = new wpdb('username', 'password', 'dbname', 'host');

    $query = "SELECT post_content, guid FROM myprefix_posts
        WHERE post_status = 'publish'
        AND post_type = 'page'";

    $myposts = $wpdbtest->get_results($query, OBJECT);
        foreach($myposts as $mypost)
        echo "{$mypost->post_content}";
    ?>

I put this code into my page template and I even got the post_content output. But as far as I am concerned, this is NOT what I was looking for. Shortcodes won't be parsed and performance may be a problem too.

Do you guys know any possible way, to make wordpress parse shortcodes that were received out of an external database? As I said, the two wordpress installations are identical, so al shortcodes are well defined in each functions.php.

Thank you!

share|improve this question
    
Are they on the same domain? If not, you could use »WebHooks« (Plugin in the repo for that), or the xml-rpc interface, or just the WordPress HTTP API. Anyway: Please edit your post and add as much info and details and what you've tried so far. Thanks. –  kaiser Sep 19 '12 at 15:30
add comment

1 Answer

up vote 1 down vote accepted

On your edit2:

If it's exactly the same, could you add

echo apply_filters('the_content', {$mypost->post_content});

to apply the_content filter to parse the shortcodes?

Also, why not use the multi-site feature of WordPress? If so much is identical, it seems more straightforward to update if your code is not duplicated. And for shared content you could then use get_blog_post(). You can still map to individual domains so you have your url differences.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.