add_action(\'wp_ajax_nopriv_updating_heat_value\',\'updating_heat_value\');
add_action(\'wp_ajax_updating_heat_value\',\'updating_heat_value\');
add_action(\'wp_ajax_update_reading_history\',\'update_reading_history\');
function update_reading_history() {
global $post;
if(is_normal_post()) {
$postiddx2 = get_the_ID();
$thepost = get_post($postiddx2);
if(!(wp_is_post_revision($thepost)))
{
$userid1 = get_current_user_id();
$loggedreadinghistory = get_user_meta($userid1, \'readinghistory\', true);
if($loggedreadinghistory == \'\') {
$readinghistory = $postiddx2;
update_user_meta($userid1, \'readinghistory\', $readinghistory);
}
else
{
$readinghistory = $loggedreadinghistory;
$readinghistory = $readinghistory.\',\'.$postiddx2;
update_user_meta($userid1, \'readinghistory\', $readinghistory);
}
}
}
exit();
}
function updating_heat_value()
{
global $post;
if(is_single())
{
$postiddx = get_the_ID();
$timenow = time();
$heatvaluedate = get_post_meta($postiddx, \'heatvaluedate\');
if((get_post_meta($postiddx, \'heatvalue\') == \'\') || $heatvaluedate == \'\')
{
update_post_heat_value($postiddx);
}
elseif(($timenow - $heatvaluedate) >= 600)
{
update_post_heat_value($postiddx);
}
}
exit();
}
我想将此PHP代码添加到wp\\U ajax挂钩中,但我不知道这些函数是如何执行的。有什么问题吗?这是这样做的最佳方式吗?WP_AJAX Hook不执行此PHP代码
1 个回复
最合适的回答,由SO网友:vancoder 整理而成
您正在尝试使用get_the_ID
在回调函数中,但是get_the_ID
只能在循环内工作。
您应该将post ID显式地发送到回调函数。
结束