使用自定义用户元字段中的Ajax删除值无法在Wordpress中使用

时间:2018-11-09 18:04:14

标签: php ajax wordpress

我已经向自定义用户元字段添加了一个值。之后,我试图删除要使用ajax代码删除的自定义元字段。

<form id="um_form" method="POST">
        <p>
            <label for="um_key">
                User Meta Value:&nbsp;&nbsp;
                <input type="text" name="um_key" id="um_key" value="<?php echo get_the_id()" style="width:100%;" />
            </label>
            <input type="submit" value="Submit" />
        </p>
    </form>

然后复制所有内容并通过stackoverflow

完成

仅更改是在更新字段停止工作后的更新字段。

下面是我如何通过wordpress查询获取值的方法。

get_post_meta( $post_id, "_post_like_count", true );

functions.php代码是

function um_modifications_callback() {

    // Ensure we have the data we need to continue
    if( ! isset( $_POST ) || empty( $_POST ) || ! is_user_logged_in() ) {

        // If we don't - return custom error message and exit
        header( 'HTTP/1.1 400 Empty POST Values' );
        echo 'Could Not Verify POST Values.';
        exit;
    }

    $user_id        = get_current_user_id();                            // Get our current user ID
    $um_val         = sanitize_text_field( $_POST['first_name'] );      // Sanitize our user meta value
    $um_user_email  = sanitize_text_field( $_POST['user_email'] );      // Sanitize our user email field

    update_user_meta( $user_id, '_post_like_count', $um_val );                // Update our user meta
    wp_update_user( array(
        'ID'            => $user_id,
        'user_email'    => $um_user_email,
    ) );

    exit;
}

add_action( 'wp_ajax_nopriv_um_cb', 'um_modifications_callback' );
add_action( 'wp_ajax_um_cb', 'um_modifications_callback' );

0 个答案:

没有答案