Support » Fixing WordPress » 2 WP installs -> 1 db, how to…..?

  • Hi,

    I have installed 2 WP (one per website) which shares 1 DB. The WP tables are unique by their prefix (like websiteA_ vs websiteB_).

    But now for the fun part, for certain websiteB pages/posts i like to use the corresponding websiteA page/post content.

    – How or what would be the best way to accomplish this??
    – Can i alter $myPosts = new WP_Query($args); ,to use websiteA tables based on the unique prefix for websiteA tables, in websiteB functions.php???

    Any tips??

Viewing 7 replies - 1 through 7 (of 7 total)
  • I would suggest not trying to pull posts directly from the other blog’s database. That way lies madness…

    Instead, do what you’d do if the sites weren’t using the same db or server: RSS Syndication. There are several syndication plugins that you can look into that can be configured to pull posts from the feed of another blog. (Feedwordpress is one I used years ago but I’m not sure if it is current or not)

    good thinking, thanks for pointing me into the right direction.

    i came up with this function but your RSS suggestion is much better.
    But the RSS way means i
    – must enable rss on websiteA? websiteA/feed/
    – how to get posts per category? (how do i parse the rss xml nodes???)

    I will take a look into the plugins, meanwhile here’s the function i came up with:

    function to get content from fashionsolution db
    	- let op andere prefix table
    function getParallelContent($prefix, $showposts, $category_name){
    	global $wpdb;
    	//$prefix = "wp_";
    	$sql = "SELECT ".$prefix."posts.ID, ".$prefix."posts.post_title, ".$prefix."posts.post_content, ".$prefix."posts.post_name,".$prefix."posts.post_type FROM ".$prefix."posts
          JOIN ".$prefix."term_relationships
          ON ".$prefix."posts.ID = ".$prefix."term_relationships.object_id
          JOIN ".$prefix."term_taxonomy
          ON ".$prefix."term_relationships.term_taxonomy_id = ".$prefix."term_taxonomy.term_taxonomy_id
          AND (".$prefix."term_taxonomy.taxonomy = 'post_tag' OR ".$prefix."term_taxonomy.taxonomy = 'category')
          JOIN ".$prefix."terms
          ON ".$prefix."term_taxonomy.term_id = ".$prefix."terms.term_id
    	  WHERE ".$prefix."terms.slug = '".$category_name."' AND post_type = 'post' ORDER BY ".$prefix."posts.ID DESC LIMIT ".$showposts.";
    	$rows = $wpdb->get_results( $sql );
    	return $rows;

    should i use simplepie perhaps?

    simplepie is an option if you don’t want to just use an pre-existing plugin I suppose.

    As for the question about category, by default every category has a feed. Just use for the RSS feed to it.

    As for the question about category, by default every category has a feed. Just use for the RSS feed to it.

    WOW, that’s a WP feature i didn’t know existed. Again thanks. i am going to try the simplepie route, first.

    Installed the simple pie core plugin and put this in functions.php.

    Not yet the right layout, but it might point some else in the right direction.

    function getRSScontent($rss, $numOfItems) {
    	// We'll process this feed with all of the default options.
    	$feed = new SimplePie();
    	// Set which feed to process.
    	// Run SimplePie.
    	// This makes sure that the content is sent to the browser as text/html and the UTF-8 character set (since we didn't change it).
     	$res = '';
    	Here, we'll loop through all of the items in the feed, and $item represents the current item in the loop.
    	foreach ($feed->get_items() as $item):
    		if($i < $numOfItems):
    			$res .='<div class="item">
    					<h2><a href="'.$item->get_permalink().'">'. $item->get_title().'</a></h2>
    					<p>'. $item->get_description().'</p>
    					<p><small>Posted on '. $item->get_date('j F Y | g:i a').'</small></p>
    	return $res;


    hmm, why has WP 2.9.2 no page feeds????

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘2 WP installs -> 1 db, how to…..?’ is closed to new replies.