这个new_to_publish
钩子有一个参数:$post
. 使用它来获取帖子id。这是您编辑的代码:
add_action( \'new_to_publish\', \'send_notification\', 1, 1 );
function send_notification( $post ){
$post_id = $post->ID;;
global $wpdb;
$sel2 = mysql_query("select * from gcm_users");
while($data1 = mysql_fetch_assoc($sel2))
{
$key = $data1[\'gcm_regid\'];
include_once \'../blogdroid/config.php\';
include_once \'../blogdroid/GCM.php\';
$gcm = new GCM();
$sel = mysql_query("select * from ".$wpdb->prefix."posts where ID=\'$post_id\'");
$data = mysql_fetch_assoc($sel);
$Pname = $data[\'post_title\'];
$registatoin_ids = array($key);
if($Pname != \'Auto Draft\')
{
$message = array("blog" => \'New Blog Arrived \'.$Pname );
$result = $gcm->send_notification($registatoin_ids,$message);
}
}
}
}