Создал плагин для постинга в дискорд. Отдельный тип записи, со своими допполями. Тестировал вывод полей в цикле (вывод всех полей в archive-cta.php) - выводятся. в плагине же не работает. То есть - постить постит, но допполя не вытягивает. get_the_title($postid) вытянуло без проблем.
function cta_send_notification( $new_status, $old_status, $post ) {
$sxss=get_post_type();
if(
'publish' === $new_status &&
'publish' !== $old_status &&
$sxss == 'cta'
) {
function postToDiscord($message)
{
$data = array(
"content" => $message,
"username" => "CTA PING BOT",
);
$curl = curl_init("https://discordapp.com/api/webhooks/idchannel/key");
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
return curl_exec($curl);
curl_close($curl);
}
$postid =get_the_ID();
$taste=get_the_title($postid);
global $post;
// get post meta
$pstmt1=get_post_meta( $postid, 'wpcf-fleetformat', true );
$message="**";
$message.=$taste;
$message.=' **
```
--------------------------------------------------------------
Location: UALX-3
Datetime: 10.08.18 20:00 ET
FleetFormat: '.$pstmt1.'
FC: TBD
--------------------------------------------------------------
```';
postToDiscord($message);
}
}
add_action( 'transition_post_status', 'cta_send_notification', 10, 3 );
подозреваю что поля записываются в бд после публикации. и они еще не попадают в бд, а я пробую их получить
function cta_send_notification( $post_id ) {
if ( wp_is_post_revision( $post_id ) || get_post($post_id)->post_status != 'publish' )
{
return;
}
function postToDiscord($message){
$data = array(
"content" => $message,
"username" => "CTA PING BOT",
);
$curl = curl_init("https://discordapp.com/api/webhooks/айди/кей");
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
return curl_exec($curl);
curl_close($curl);
};
$postid =get_the_ID();
$taste=get_the_title($postid);
// get post meta
$pstmt1=get_post_meta($postid, 'wpcf-date-time', true );
$message="**";
$message.=$taste;
$message.=' **
```
------------------------------
ID '.$postid.'
Title '.$taste.'
post meta : '.$pstmt1.'
------------------------------
```';
postToDiscord($message);
}
add_action( 'save_post_cta', 'cta_send_notification', 99999, 1 );
Переделал под save_post. результат тот же. айди и тайтл нормально тянет. допполя не вытягивает