WordPress.org

Ready to get started?Download WordPress

Forums

2 WP installs -> 1 db, how to.....? (8 posts)

  1. DDT
    Member
    Posted 3 years ago #

    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??

  2. Chris_K
    Member
    Posted 3 years ago #

    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)

  3. DDT
    Member
    Posted 3 years ago #

    @Chris_k,
    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???)
    <category><![CDATA[News]]></category>

    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
    		LEFT
          JOIN ".$prefix."term_relationships
          ON ".$prefix."posts.ID = ".$prefix."term_relationships.object_id
    
          LEFT
          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')
    
          LEFT
          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;
    }
    }
  4. DDT
    Member
    Posted 3 years ago #

    should i use simplepie perhaps?

  5. Chris_K
    Member
    Posted 3 years ago #

    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 http://blogname.com/category/categoryName/feed for the RSS feed to it.

  6. DDT
    Member
    Posted 3 years ago #

    As for the question about category, by default every category has a feed. Just use http://blogname.com/category/categoryName/feed 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.

  7. DDT
    Member
    Posted 3 years ago #

    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.
    	$feed->set_feed_url($rss);
    	// Run SimplePie.
    	$feed->init();
    	// 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).
    	$feed->handle_content_type();
    
     	$res = '';
    	/*
    	Here, we'll loop through all of the items in the feed, and $item represents the current item in the loop.
    	*/
    	$i=0;
    	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>
    				</div>';
    		endif;
    		$i++;
     	endforeach;
    	return $res;
    }

    regards

  8. DDT
    Member
    Posted 3 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic