[英]How to insert into Wordpress Database on click of link?
I've got two variables that are set once the wordpress page loads. 加载wordpress页面后,我将设置两个变量。 How can I initiate the insertion of the record once the link is clicked?
单击链接后,如何启动记录的插入? Everything I've read so far requires a form.
到目前为止,我阅读的所有内容都需要一个表格。 This is the code I have so far:
这是我到目前为止的代码:
<?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() )
Add a get variable to the end of your link. 在链接的末尾添加一个get变量。
Eg 例如
<a href="mylink.com/?track_click">Click to Insert into Database</a>
Then in functions.php add some code on init to check for this and run code. 然后在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' );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.