SAVE_POST_PRODUCT操作未触发

时间:2022-02-02 作者:Alex Knopp

当我保存“a”时,我试图保存一些元值;“产品”;岗位类型。然而,我的save\\u post操作似乎没有启动。我说错了吗?下面类中的代码显示了admin fine中的元框,但它只是不调用save。

<?php
/**
 * Called from main plugin file
 */
function knp_load_first() {

    new KnpvAdminProductMeta();

}
add_action(\'plugins_loaded\', \'knp_load_first\');

/**
 * Output meta boxes and save meta values
 */
class KnpvAdminProductMeta {

    function __construct(){

        //Save the meta values
        add_meta_box(\'knpv_submission_fields\', \'Editable Submission Fields\', array($this, \'knpv_submission_fields\'), \'product\', \'normal\', \'default\');
        add_action( \'save_post\', [$this, \'knpv_save_meta_fields\'], 10, 3 );

    }

    public function knpv_save_meta_fields(){

        //For tesitng
        //This should kill the script and output the posted values
        //It doesnt!
        pre($_POST);
        die();

        //Update the post meta
        update_post_meta($post_id, \'submissiondata\', $_POST[\'submissiondata\']);
        update_post_meta($post_id, \'included-with\', $_POST[\'included-with\'] );

    }

}

1 个回复
SO网友:Alex Knopp

已更改

add_action(\'plugins_loaded\', \'knp_load_first\');

add_action(\'init\', \'knp_load_first\');
一切都很好!