Two blogs – One database – How to extract data?
-
Here is my situation. I’ve installed two seperate WP v2.0.1 blogs to a single mysql database. One is defaulted to “wp_” the other is “rv_”.
Within both install directories I have “my-hacks.php” which contains a function that gives an excerpt from a post. From the main page of my website I call each of the functions (that are named differently) to show the latest post.
Problem is the only one that is working is the function from the original install (wp_ prefixed tables). My question is do I have to alter the code to make it work with the “rv_” prefixed tables?
Here is the code (note both are the same only the functions are named differently). Oh yeah, I also know the code (which isn’t mine) isn’t exactly optimized . . .
function get_recent_posts($no_posts = 1, $before = '<li>', $after = '</li>', $show_pass_post = false, $skip_posts = 0) {
global $wpdb, $tableposts, $tablepost2cat;
$request = "SELECT ID, post_title, post_content, category_id FROM $tableposts, $tablepost2cat WHERE post_status = 'publish' AND (post_id = ID AND category_id != '5')";
if(!$show_pass_post) { $request .= "AND post_password ='' "; }
$request .= "ORDER BY post_date DESC LIMIT $skip_posts, $no_posts";
$posts = $wpdb->get_results($request);
$output = '';
foreach ($posts as $post) {
$string = ($post->post_content);
$cut = implode(" ", array_slice(preg_split("/s+/", $string), 0, 15)); //change last number to # of words you want displayed
$post_title = stripslashes($post->post_title);
$post_excerpt = stripslashes($post->post_excerpt);
$permalink = get_permalink($post->ID);
//$test = str_word_count($post->post_content)
$output .= $before . '<font size=3><b>' . $post_title . '</b></font>' . $after;
$output4 .= $before . '<div class="rightColumnSplit"></div>';
$output1 .= $before . $cut . ' . . .' . $after;
//$output .= $before . '<a href="' . $permalink . '" rel="bookmark" title="Permanent Link: ' . $post_excerpt . '">' . $post_excerpt . '</a>' . $after;
$output3 .= $before . '<div class="rightColumnSplit"></div>';
$output2 .= $before . '<center><a href="' . $permalink . '" rel="bookmark" title="Permanent Link: ' . ReadMore . '">' . Read_More . '</a></center>' . $after;}
echo $output;
echo $output4;
echo $output1;
//echo implode(" ", array_slice(preg_split("/s+/", $string), 0, 10)); //change last # for # of words to display
echo $output3;
echo $output2;
}Thanks for any insight.
-mike
The topic ‘Two blogs – One database – How to extract data?’ is closed to new replies.