WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Post IDs and Multiple Blogs (5 posts)

  1. uplandporter
    Member
    Posted 8 years ago #

    I have multiple blogs sharing a database. Is it possible to call one or more of Blog A's post id's from Blog B -- so that the post is displayed as part of Blog B?

  2. Kafkaesqui

    Posted 8 years ago #

    Call them specifically by their post ID, or just by most recent posts and so on?

    If you're looking to display Blog A's posts on Blog B but not in a way that the posts appear intermixed, then it's possible you could do it in a couple ways.

    The typical way is to grab the RSS feed (for Blog A) using an RSS aggregation tool or plugin. You'll find a number of them here:

    http://codex.wordpress.org/Plugins/Syndication

    Another not so known method is to use a custom SQL query outside the regular post loop. For example:

    <?php
    $a_posts = $wpdb->get_results("SELECT * FROM a_posts WHERE post_status = 'publish' ORDER BY post_date DESC LIMIT 5");
    foreach($a_posts as $post) :
    setup_postdata($post);
    ?>

    ~Insert template tags and any other "loop-related" elements here.~

    <?php endforeach; ?>

    Just change a_posts in the SELECT line to the posts table name used for Blog A. This will hit some limitations such as permalinks (there are ways around that), or setup_postdata() not being able to properly collect custom field info for a post.

    If you need to incorporate Blog A's posts into Blog B in some more complete (i.e. mixed) fashion, you may want to look at a utility like FeedWordPress (found on the Plugins link above).

  3. uplandporter
    Member
    Posted 8 years ago #

    Many thanks, Kafkaesqui -- I appreciate the thorough help! I'll try out both methods.

  4. uplandporter
    Member
    Posted 8 years ago #

    But, now that I've started playing with this, a follow-up... What would change if I wanted to pull a specific post ID from Blog A into Blog B?

  5. uplandporter
    Member
    Posted 8 years ago #

    Aha -- I got it! I just changed the query to select the post ID.

    $a_posts = $wpdb->get_results("SELECT * FROM a_posts WHERE ID = #");

    Now I have a variety of tools at my disposal for sharing posts between these blogs. Thanks so much!

    And this gives me more reason to explore db queries...

Topic Closed

This topic has been closed to new replies.

About this Topic