0 Replies - 8552 Views - Last Post: 15 January 2012 - 08:27 PM Rate Topic: -----

#1 co0l   User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 18
  • Joined: 10-May 11

Wordpress MU (Displaying and Updating data in plugin's table).

Posted 15 January 2012 - 08:27 PM

Hello,
I have Wordpress 3.3.1 multi site installed on my local server, and I have one main blog and 1 sub blog on it.

I am have one voting plugin (emo vote) installed which creates a new tale in database for each sub blog. That table includes a unique row for each post in that sub blog.

Now I am displaying posts of the sub blog on my main blog, the post works fine but the voting data does not get displayed on the main blog. the plugin uses the get_option function for displaying and updating the voting data in specific sub blog. I want to use that plugin on my main blog to display and update the data in the sub blog's table in database.

I am using custom function to display the posts of the sub blog on main blog, here is that function:

function show_videoswall_posts( $blog_id ) {
	$blog_details = get_blog_details($blog_id);
	if($blog_details):
		switch_to_blog( $blog_id );
		query_posts( 'orderby=date&order=dec&showposts=10' );
		if( have_posts()):
			while(have_posts()): the_post();
			?>
			
		<!-- post layout -->
	<a href="<?php the_permalink(); ?>" title="<?php printf( __('%s', 'author'), the_title_attribute('echo=0') ); ?>"><?php the_title(); ?></a>
		
<?php if (function_exists('emo_vote_display')) emo_vote_display('No votes', '1 vote', '% votes'); ?>
			
		</div><!-- END entry -->		

		
		<?php if(is_sticky()) { ?>
			<div class="entry"><p><?php _e('This is a sticky post!', 'funwall'); ?> <!-- <a href="<?php the_permalink(); ?>" class="more-links"><?php _e('continue reading?', 'funwall'); ?></a> --></p></div>
		<?php } ?>
	</div><!-- END post -->
		<!-- post layout ends -->
		
			<? endwhile;
		endif;
		restore_current_blog();
		wp_reset_query();
	else:
		echo 'No items found, Please report this problem.';
	endif;	
restore_current_blog();
}




Here is the plugin's function which which is displaying and update the voting data:
function emo_vote_display($zero='No votes',$one='1 vote',$more='% votes') {
	global $wpdb;
	$vote = strval($_GET['emo']);
	$options = get_option(EMO_OPTIONS);
	$titles = split('[#]+',$options['titles']);
	$post_id = get_the_ID();
	$question = get_post_meta($post_id,'emo-vote',true);
	$return = !$question ? '<div class="emo-vote" id="emo-vote_'. $post_id .'">' : '<div class="emo-vote" id="emo-vote_'. $post_id .'"><p class="emo-vote-title">'. $question .'</p>';
	
	if($options['list'] > 0)
		$values = $wpdb->get_row($wpdb->prepare("SELECT CONCAT(round(vote_0/vote_total*100,0),'%') as vote_0, CONCAT(round(vote_1/vote_total*100,0),'%') as vote_1, CONCAT(round(vote_2/vote_total*100,0),'%') as vote_2, CONCAT(round(vote_3/vote_total*100,0),'%') as vote_3, CONCAT(round(vote_4/vote_total*100,0),'%') as vote_4, vote_total FROM {$wpdb->emo_vote} WHERE post_ID = %d",$post_id),ARRAY_A);
	else
		$values = $wpdb->get_row($wpdb->prepare("SELECT vote_0, vote_1, vote_2, vote_3, vote_4, vote_total FROM {$wpdb->emo_vote} WHERE post_ID = %d",$post_id),ARRAY_A);
	
	if(is_emo())
		$disabled = 'disabled="disabled" ';
	
	foreach ($titles as $title) {
		list($key, $val) = split(':', $title);
		
		if ($_COOKIE['emo_vote-'. $post_id] == $key)
			$checked = 'checked="checked" ';
		
		$value = ($values['vote_'. $key]) ? $values['vote_'. $key] : (($options['list'] > 0) ? '0%' : '0');
		$return .= '<input type="checkbox" id="emo_vote-'. $key . $post_id .'" name="emo_vote-'. $key .'" value="'. $key .'" class="emo_vote-'. $key .'" '. $disabled .''. $checked .'/>';
		$return .= '<label for="emo_vote-'. $key . $post_id .'">'. $val .'</label> ';
		$return .= '<span class="emo_vote-'. $key .'">('. $value .')</span>';
		$checked = null;
	}
	
	if($options['total'] > 0) {
		$total = $values['vote_total'] > 1 ? str_replace('%',$values['vote_total'],$more) : ($values['vote_total'] == 1 ? $one : $zero);
		$return .= '<input class="emo_locale" type="hidden" value="'. $zero .'#'. $one .'#'. $more .'" /><div class="emo_vote_total">'. $total .'</div>';
	}
	
	$return .= '<input class="emo_url" type="hidden" value="'. emo_path() .'" /></div>';
	
	if(is_single() && !is_emo() && strlen($vote) > 0)
		$return .= '<script type="text/javascript">jQuery(document).ready(function(){jQuery(\'body\').emoDialog({option:'. $vote .',str:\''. __('Feeling',EMO_LOCAL) .' '. $_GET['vote'] .'\'});});</script>';
	
	echo $return;
}



Is This A Good Question/Topic? 0
  • +

Page 1 of 1