fix(analytics): Add permalink building to admin-ajax fallback

When JavaScript falls back to admin-ajax.php instead of the fast
search-endpoint.php, results were returned with empty permalinks.
This caused click tracking to log URLs in /?p=ID format.

Now both endpoints build proper permalinks using post_name:
- search-endpoint.php (fast): Already had the fix
- admin-ajax fallback: Added permalink building (lines 182-203)

Also flushed Redis cache to clear stale results.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
FrankZamora
2025-12-03 11:20:03 -06:00
parent 81d65c0f9a
commit 255d720db6

View File

@@ -179,6 +179,29 @@ final class ROI_APU_Search_Plugin
$offset = ($page - 1) * $per_page;
$results = $search->run($term, $per_page, $offset, $category_ids);
// Build permalinks for each result (search engine returns empty permalink)
$site_url = rtrim(home_url(), '/');
$permalink_structure = get_option('permalink_structure', '/%postname%/');
foreach ($results['rows'] as &$row) {
if (empty($row['permalink'])) {
$postName = $row['post_name'] ?? '';
if (empty($postName)) {
$row['permalink'] = $site_url . '/?p=' . $row['ID'];
continue;
}
// Build according to permalink structure
if (strpos($permalink_structure, '%post_id%') !== false) {
$row['permalink'] = $site_url . '/' . $row['ID'] . '/';
} else {
$row['permalink'] = $site_url . '/' . $postName . '/';
}
}
}
unset($row);
// Log search for analytics
$analytics_cfg = ROI_APU_Search_Analytics::get_config();
$search_id = ROI_APU_Search_Analytics::logSearch(