WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] pulling data from multiple blogs/multiple db’s from a single static page

[Resolved] pulling data from multiple blogs/multiple db’s from a single static page

  • Hey folks,

    I’ve been slaving over this issue the whole day and can’t seem to find any solution for it.

    URL: http://sjbci.org/index_test.php

    Notice the sidebar boxes containing Devotions and News & Announcements entries. I did declare different wp-config.php’s, it seems that which db is declared first gets to persist its data and the other $wpdb->get_posts gets to keep the previous data as if it never queried the second db.

    here’s the code of the sidebar entries:

    <div class="mSide"><strong>Devotions </a></strong><br />
    
    <?php
    $how_many=5; //How many posts do you want to show
    require_once("./devotions/wp-config.php"); // Change this for your path to wp-config.php file ?>
    <?
    $devotions=$wpdb->get_results("SELECT <code>ID</code>,<code>post_title</code> FROM $wpdb->posts WHERE <code>post_status</code>= \"publish\" ORDER BY 'ID' DESC LIMIT ".$how_many);
    foreach($devotions as $devo){
    print ("• ");
    print ("<a href=\"");
    echo get_permalink($devo->ID);
    print ("\">$devo->post_title</a>");
    print ("<br />");
    } ?>
    
    </div>
    
    	<div class="mSide"><strong>News & Announcements</strong><br />
    
    <?php
    $how_many=5; //How many posts do you want to show
    require_once("./news/wp-config.php"); // Change this for your path to wp-config.php file ?>
    <?
    $ijk = 0;
    $news=$wpdb->get_results("SELECT <code>ID</code>,<code>post_title</code> FROM $wpdb->posts
    WHERE <code>post_status</code>= \"publish\" ORDER BY 'ID' DESC LIMIT ".$how_many);
    foreach($news as $np){
    $ijk++;
    print ("$ijk. ");
    print ("<a href=\"");
    echo get_permalink($np->ID);
    print ("\">$np->post_title</a>");
    print ("<br />");
    } ?>
    	</div>

    here are my prefixes,
    devotions: $table_prefix = ‘wp_’;
    news: $table_prefix = ‘news_’;

    What’s the best way to accomplish this without using XML. I know I can always cURL the feed then do some domdocument and xpath mumbo-jumbo in PHP but I don’t want to do that.

    Any thoughts?

Viewing 4 replies - 1 through 4 (of 4 total)
  • anyone?

    had to turn to the dark side on this one. i ended up using the built-in WP XML parser.

    <?php require_once('blah..blah/wp-includes/rss.php'); ?>
    <?php $rss = fetch_rss('your feed here');
    $ijk = 0;
    ?>
    
    <?php foreach ( $rss->items as $item ) : ?>
    <?php print ("• ");?>
    <a href='<?php echo $item['link']; ?>'
    title='<?php echo $item['title']; ?>'>
    <?php echo $item['title']; ?>
    </a>
    <br /?>
    <?php
    $ijk++;
    // i want to limit the results to 5
    if ($ijk == 5) {
    break;
    } ?>
    <?php endforeach; ?>

    Well, I can’t help with the way you want to do it, but if you would consider doing it with RSS, I’d suggest SimplePie. It’s really easy and works a heck of a lot better that the built in magpie stuff in WordPress.

    Try this multifeed version:

    Sorting multiple feeds by time and date

    thanks mr blank. the only reason why i did what i did was because i needed a quick fix and fast. i’ll take a look into this solution and will try to implement it.

    again, thanks.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Resolved] pulling data from multiple blogs/multiple db’s from a single static page’ is closed to new replies.
Skip to toolbar