{"id":37,"date":"2026-04-08T14:16:47","date_gmt":"2026-04-08T14:16:47","guid":{"rendered":"https:\/\/louthlgfa.ie\/?page_id=37"},"modified":"2026-04-08T14:49:24","modified_gmt":"2026-04-08T14:49:24","slug":"division-2-league","status":"publish","type":"page","link":"https:\/\/louthlgfa.ie\/?page_id=37","title":{"rendered":"Division 2 League"},"content":{"rendered":"\n<div id=\"compAll2\">Loading fixtures &#038; results\u2026<\/div>\n\n<script>\n(async () => {\n    const apiKey = \"foir_prod_NDtiJNVWyQpxRRujIXMrCOZntNaqZfflFjihYbiLtqilV\";\n    const competitionId = \"bf960007-76e7-4762-9e61-54ec0396d503\";\n\n    const url = `https:\/\/api.foireann.ie\/open-data\/v1\/fixtures?size=500`;\n\n    const response = await fetch(url, {\n        headers: {\n            \"Authorization\": \"Bearer \" + apiKey,\n            \"Accept\": \"application\/json\"\n        }\n    });\n\n    const json = await response.json();\n    let fixtures = json.data || [];\n\n    \/\/ Filter to this competition\n    fixtures = fixtures.filter(f =>\n        f.competition?.id === competitionId\n    );\n\n    if (fixtures.length === 0) {\n        document.getElementById(\"compAll2\").innerHTML =\n            \"<p>No fixtures or results found for this competition.<\/p>\";\n        return;\n    }\n\n    \/\/ Auto competition name\n    const competitionName = fixtures[0].competition?.name || \"Competition\";\n\n    \/\/ Identify result statuses\n    const resultStatuses = [\n        \"RESULT\",\n        \"RESULT_AFTER_EXTRA_TIME\",\n        \"RESULT_AFTER_PENALTIES\"\n    ];\n\n    \/\/ Split into results + fixtures\n    const results = fixtures.filter(f =>\n        resultStatuses.includes((f.status || \"\").toUpperCase())\n    );\n\n    const upcoming = fixtures.filter(f =>\n        !resultStatuses.includes((f.status || \"\").toUpperCase())\n    );\n\n    \/\/ Sort results newest \u2192 oldest\n    results.sort((a, b) => new Date(b.startDate) - new Date(a.startDate));\n\n    \/\/ Sort fixtures oldest \u2192 newest\n    upcoming.sort((a, b) => new Date(a.startDate) - new Date(b.startDate));\n\n    let html = `\n        <h3>${competitionName}<\/h3>\n        <p><strong>Competition ID:<\/strong> ${competitionId}<\/p>\n    `;\n\n    \/* ---------------- RESULTS SECTION ---------------- *\/\n    html += `<h4>Results<\/h4>`;\n\n    if (results.length === 0) {\n        html += `<p>No completed results yet.<\/p>`;\n    } else {\n        html += `\n            <table style=\"width:100%; border-collapse:collapse; margin-bottom:20px;\">\n                <thead>\n                    <tr>\n                        <th style=\"border:1px solid #ccc; padding:6px;\">Date<\/th>\n                        <th style=\"border:1px solid #ccc; padding:6px;\">Home<\/th>\n                        <th style=\"border:1px solid #ccc; padding:6px;\">Away<\/th>\n                        <th style=\"border:1px solid #ccc; padding:6px;\">Score<\/th>\n                    <\/tr>\n                <\/thead>\n                <tbody>\n        `;\n\n        results.forEach(f => {\n            const date = new Date(f.startDate).toLocaleString();\n            const home = f.homeTeam?.name || \"\";\n            const away = f.awayTeam?.name || \"\";\n            const score = `${f.homeScore?.display || \"\"} - ${f.awayScore?.display || \"\"}`;\n\n            html += `\n                <tr>\n                    <td style=\"border:1px solid #ccc; padding:6px;\">${date}<\/td>\n                    <td style=\"border:1px solid #ccc; padding:6px;\">${home}<\/td>\n                    <td style=\"border:1px solid #ccc; padding:6px;\">${away}<\/td>\n                    <td style=\"border:1px solid #ccc; padding:6px;\">${score}<\/td>\n                <\/tr>\n            `;\n        });\n\n        html += \"<\/tbody><\/table>\";\n    }\n\n    \/* ---------------- FIXTURES SECTION ---------------- *\/\n    html += `<h4>Upcoming Fixtures<\/h4>`;\n\n    if (upcoming.length === 0) {\n        html += `<p>No upcoming fixtures.<\/p>`;\n    } else {\n        html += `\n            <table style=\"width:100%; border-collapse:collapse;\">\n                <thead>\n                    <tr>\n                        <th style=\"border:1px solid #ccc; padding:6px;\">Date<\/th>\n                        <th style=\"border:1px solid #ccc; padding:6px;\">Home<\/th>\n                        <th style=\"border:1px solid #ccc; padding:6px;\">Away<\/th>\n                    <\/tr>\n                <\/thead>\n                <tbody>\n        `;\n\n        upcoming.forEach(f => {\n            const date = new Date(f.startDate).toLocaleString();\n            const home = f.homeTeam?.name || \"\";\n            const away = f.awayTeam?.name || \"\";\n\n            html += `\n                <tr>\n                    <td style=\"border:1px solid #ccc; padding:6px;\">${date}<\/td>\n                    <td style=\"border:1px solid #ccc; padding:6px;\">${home}<\/td>\n                    <td style=\"border:1px solid #ccc; padding:6px;\">${away}<\/td>\n                <\/tr>\n            `;\n        });\n\n        html += \"<\/tbody><\/table>\";\n    }\n\n    document.getElementById(\"compAll2\").innerHTML = html;\n})();\n<\/script>\n\n","protected":false},"excerpt":{"rendered":"<p>Loading fixtures &#038; results\u2026<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-37","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/louthlgfa.ie\/index.php?rest_route=\/wp\/v2\/pages\/37","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/louthlgfa.ie\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/louthlgfa.ie\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/louthlgfa.ie\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/louthlgfa.ie\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=37"}],"version-history":[{"count":3,"href":"https:\/\/louthlgfa.ie\/index.php?rest_route=\/wp\/v2\/pages\/37\/revisions"}],"predecessor-version":[{"id":42,"href":"https:\/\/louthlgfa.ie\/index.php?rest_route=\/wp\/v2\/pages\/37\/revisions\/42"}],"wp:attachment":[{"href":"https:\/\/louthlgfa.ie\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=37"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}