无法使用transition_post_status钩子获取post_id

时间:2019-01-19 06:54:18

标签: wordpress

无法获取$ post-> ID,但可以获取post_title和永久链接。 我正在创建新帖子,并尝试在发布新帖子时获取post_id。

add_action( 'transition_post_status', 'send_notification', 10, 3 );

function send_notification( $new_status, $old_status, $post ) {
    if ( 'publish' === $new_status && 'publish' !== $old_status ) {
        $postdata = array();
        $postdata['title'] = $post->post_title;
        $postdata['permalink'] = get_permalink($post);
        $post_id = $post->ID;
        $term_list = wp_get_post_terms($post_id, 'countries', array("fields" => "ids"));
        $catstr = implode (",", $term_list);
        $postdata['catstr'] = $catstr;
    }
}

0 个答案:

没有答案