Support » Fixing WordPress » Post IDs and Multiple Blogs

  • Resolved uplandporter


    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?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Kafkaesqui


    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:

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

    $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) :

    ~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).



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



    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?



    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…

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Post IDs and Multiple Blogs’ is closed to new replies.