Ask your WordPress questions! Pay money and get answers fast! (more info)

Sync publish function to other sites. WordPress

  • SOLVED

I need a small piece of addon code to connect and sync to another db within the following:

global $post,$wpdb;
$postid = $post->ID;
$data = $_POST['_dappcf_i_priceone'];
update_post_meta($postid,'price',$data);
$tablename="wp_cart66_products";
if($post->post_type == "post" && strlen( get_post_meta($postid, 'price', true))>0 )
{
$id = $wpdb->get_var("SELECT id FROM ".$tablename." WHERE id=".$postid);
$cny = get_post_meta($postid, 'price', true);
/*Shipping rate */
if( $cny < 21 )
$shipping = 9*1.2;


else if( $cny >= 20 && $cny < 31 )

$shipping = 18.40*1.2;

else if( $cny >= 30 && $cny < 100 )

$shipping = 14.00*1.2;

else if( $cny >= 100 && $cny < 200 )

$shipping = 16.69*1.2;


else if( $cny >= 200 && $cny < 250 )

$shipping = 19.40*1.2;

else if( $cny >= 250 && $cny < 300 )

$shipping = 20.90*1.2;


else if( $cny >= 300 )
$shipping = 21.90*1.2;

/*Exchange rate CNY to EURO */
$cny_to_euro = 7.78;
$euro = $cny / $cny_to_euro ;
$price = $euro + $shipping;
$price = number_format($price,2);
$data=array(
'id'=>$postid,
'item_number'=>get_post_meta($postid, 'scode', true),
'name'=>$post->post_title,
'price'=>$price,
'options_1'=>get_post_meta($postid, 'variations', true),
'options_2'=>get_post_meta($postid, 'options2', true),
'shipped'=>'1',
);
$where = array("id" => $postid);
// Possible format values: %s as string; %d as decimal number; and %f as float.
$format=array( '%d', '%s', '%s', '%s', '%s', '%s', '%d');
$where_format = array( '%d' );
if($id>0){
// update
$wpdb->update( $tablename,$data, $where, $format, $where_format);
}else{
// insert
$wpdb->insert( $tablename,$data,$format);
}


<strong>other db info is:</strong>

( 'username' => 'xxx' , 'password' => 'xxx' , 'db_name' => 'xxx' , 'host' => 'localhost' , 'curr' => 'USD' )

Answers (2)

2013-08-12

Arnav Joy answers:

please right some more points your question is not clear


Arnav Joy comments:

if you want to connect to different db then you can use following


$db = new wpdb( 'username', 'password' , 'db_name' , 'host' );


and then you can all different functions using this new $db object.


oomskaap comments:

This puts a form on my page:




<form method="post" action="">
<?php wp_nonce_field('update_drw_postmeta','drw_inventory'); ?>
<label>CNY</label>
<?php edit_post_link(__('{Quick Edit}'), ''); ?>
<?php global $post;
$post_id = $post->ID;
$priceone = get_post_meta($post_id,'price',true); ?>
<input type='text' name='_dappcf_i_priceone' value='<?php echo $priceone ?>' />
<input type="hidden" name='update_me' value="yes"/>
<input type='submit' value='save' />
</form>


<?php } ?>


and when I click save, it write the top function to the database. I want an extra line of code in the function that will write the same function above into ANOTHER database.


oomskaap comments:

Thanks!, I seem to have got it working now.

2013-08-12

Hariprasad Vijayan answers:

So you want to insert same information in to another database. Right?