繁体   English   中英

WordPress在wp_die之后发布帖子

[英]WordPress publishes post after wp_die

我正在尝试检查$ _POST中的tax_input是否等于字符串。 如果相同,则发布该帖子,否则我想发送带有wp_die的消息,并且不发布该帖子。

我可以看到wp_die消息,但是当我回到帖子概述时,该帖子仍在发布。

有人知道我在做什么错吗?

function check_user_post() {

    $terms = get_terms( array(
        'taxonomy' => 'activity_region',
        'hide_empty' => false,
    ) );

    $region_id = array();
    foreach ( $terms as $term ) {

        if( $term->slug == 'antwerpen' ) {
            $region_id[] = $term->term_id;
        }
    }

    $term = get_term_by( 'id', $_POST['tax_input']['activity_region'][1], 'activity_region' );

    if( empty( $term ) ) {

        wp_set_object_terms( $_POST['post_ID'], $region_id, 'activity_region', true );
        return;

    }

    if( $term->slug != 'antwerpen' ) {

        //var_dump( $_POST );
        wp_die( '<p>You can not make activities for this region.</p>', 'Error', array( 'back_link' => true ) );

        return;

    }

}

add_action( 'save_post', 'check_user_post' );

保存帖子后立即触发动作save_post。 因此,帖子已保存,之后将执行您的功能。 另请参阅: https : //codex.wordpress.org/Plugin_API/Action_Reference/save_post

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM