From 729547764e1d33b850dc86dabe40bed512a25bd5 Mon Sep 17 00:00:00 2001 From: Ryan Salazar Date: Fri, 22 May 2026 00:46:44 +0000 Subject: [PATCH] ticker: query wp_imported_posts (not native_articles) + fallback when 7d window empty --- src/app/api/ticker/beat-news/route.ts | 30 ++++++++++++++++++++------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/app/api/ticker/beat-news/route.ts b/src/app/api/ticker/beat-news/route.ts index 3b1aafb..9d61244 100644 --- a/src/app/api/ticker/beat-news/route.ts +++ b/src/app/api/ticker/beat-news/route.ts @@ -15,24 +15,38 @@ export async function GET() { const cutoff = new Date(Date.now() - 7 * 86400000).toISOString(); - const { data, error } = await sb - .from('native_articles') - .select('id, slug, title, category, published_at') + // Primary source: bb.wp_imported_posts (BB's main article table). + let { data, error } = await sb + .from('wp_imported_posts') + .select('wp_id, wp_slug, title, category, wp_published_at') .eq('status', 'published') - .gte('published_at', cutoff) - .order('published_at', { ascending: false }) + .gte('wp_published_at', cutoff) + .order('wp_published_at', { ascending: false }) .limit(30); + // Fallback: if the 7-day window is empty, show the 30 most recent + // published articles regardless of age so the ticker isn't blank. + if (!error && (data?.length ?? 0) === 0) { + const recent = await sb + .from('wp_imported_posts') + .select('wp_id, wp_slug, title, category, wp_published_at') + .eq('status', 'published') + .order('wp_published_at', { ascending: false }) + .limit(30); + data = recent.data; + error = recent.error; + } + if (error) { return NextResponse.json({ error: error.message, items: [] }, { status: 500 }); } const items = (data || []).map((a) => ({ - id: a.id, - href: `/articles/${a.slug}`, + id: String(a.wp_id), + href: `/news/${a.wp_slug}`, title: a.title, category: a.category || null, - published_at: a.published_at, + published_at: a.wp_published_at, })); return NextResponse.json(