【问题标题】:How can I update a usermeta field using a dropdown in an array?如何使用数组中的下拉列表更新 usermeta 字段?
【发布时间】:2019-01-12 18:24:08
【问题描述】:

我正在寻求使用按钮更新用户元字段的帮助。或者更好的是没有按钮,只需在下拉菜单中进行选择。我在一个数组中列出了所有用户及其字段

$users = get_users( $args );
echo '<div class="user-list">';
echo '<table><tr><th>User ID</th><th>User Name</th><th>User Email</th> 
<th>Refund Status</th><th>Update Status</th></tr>';
foreach ( $users as $user ) {
echo '<tr><th>' . esc_html( $user->ID ) . '</th><th>' . esc_html( 
$user->display_name ) . '</th><th>' . esc_html( $user->user_email ) . 
'</th><th>' . '<select><option disabled>' . esc_html( $user- 
>refund_status ) . '</option><option value="Return Received">Return 
Received</option><option value="Refund Approved">Refund 
Approved</option><option value="Refund Sent">Refund Sent</option> 
</select>' . '</th><th><button class="button" 
onClick="updateStatus();"><span class="icon">Update Status</span> 
</button></th></tr>';
}
echo '</table></div>';

如何根据下拉菜单中的选择获取更新退款状态的按钮?我遇到的问题是我不知道如何将变量和用户 ID 传递给 Javascript foreach 用户以更新状态。我做了很多阅读,但找不到我要找的东西,也许我的搜索措辞有误。任何帮助将不胜感激。

【问题讨论】:

    标签: php arrays wordpress dropdown


    【解决方案1】:

    您可以通过useridrefund status 在下拉列表中调用onchange 函数

    function FunctionName(id, status) {
    
                var data = {
                    'id': id,
                    'status':status
                };
                //=========ajax==========//
                jQuery.ajax({
                    type: 'POST',
                    url: "update.php",
                    data: data,
                    beforeSend: function () {
                    },
                    success: function (data) {
                        alert(data);
                    },
                    error: function (e) {
                    }
                });
                //=========End of ajax====//
    
    }
    

    类似的东西。在update.php 你可以运行你的查询。

    【讨论】:

    • 我将其复制并粘贴到 update.php 文件中,但没有成功。从那以后,我一直在尝试制作一个带有数据库连接的简单表单来更新元密钥。到目前为止也没有运气,但我觉得我更接近了,因为我更好地理解它。你给我的这个例子让我很困惑,但我想试着理解它。你能帮我完成它吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-27
    • 2012-06-07
    • 1970-01-01
    • 2021-01-09
    • 2021-08-25
    • 1970-01-01
    相关资源
    最近更新 更多