gpt4 book ai didi

php - 如何通过单击链接插入 WordPress 数据库?

转载 作者:行者123 更新时间:2023-11-29 13:12:06 25 4
gpt4 key购买 nike

我有两个变量在 WordPress 页面加载后设置。单击链接后如何启动记录插入?到目前为止我读过的所有内容都需要表格。这是我到目前为止的代码:

<?php 
global $post;
$wp_user_id = get_current_user_id();
$activity_post_id = $post->ID;
?>

<a href="insert_into_database_somehow">Click to Insert into Database</a>

INSERT INTO wp_activities (wp_user_id, activity_post_id, date_added) VALUES ($wp_user_id, $activity_post_id, CURDATE() )

最佳答案

将 get 变量添加到链接末尾。

例如

<a href="mylink.com/?track_click">Click to Insert into Database</a>

然后在functions.php中在init上添加一些代码来检查并运行代码。

function wpse_track_click() {
if ( ! isset( $_GET['track_click'] ) )
return false;

// add your code to run here.
}
add_action( 'init', 'wpse_track_click' );

关于php - 如何通过单击链接插入 WordPress 数据库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21957370/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com