'Missing post ID.',
));
}
if (!wp_verify_nonce($nonce, 'aitm_visit_counter_' . $post_id)) {
wp_send_json_error(array(
'message' => 'Invalid nonce.',
));
}
if (get_post_type($post_id) !== 'ai_tool') {
wp_send_json_error(array(
'message' => 'Invalid post type.',
));
}
$current_count = get_post_meta($post_id, 'visit_count', true);
$current_count = is_numeric($current_count) ? intval($current_count) : 0;
$new_count = $current_count + 1;
update_post_meta($post_id, 'visit_count', $new_count);
wp_send_json_success(array(
'post_id' => $post_id,
'visit_count' => $new_count,
));
}