<?php
    $authors = $block_query_posts->getAuthors($post_type);

    $sports_leagues = [];
    if (function_exists('sportshubGamesGetParentsGames')) {
        $sports_leagues = sportshubGamesGetParentsGames();
    }
?>

<?php if (is_array($authors) && count($authors) > 0): ?>
    <select name="author" id="author">
        <option value="">Author</option>
        <?php foreach ($authors as $author_id => $author_name): ?>
            <option value="<?php echo $author_id; ?>"><?php echo $author_name; ?></option>
        <?php endforeach; ?>
    </select>
<?php endif; ?>

<?php if (is_array($sports_leagues) && count($sports_leagues) > 0): ?>
    <select name="category" id="category">
        <option value="">Sport / Category</option>
    <?php foreach ($sports_leagues as $sport => $leagues): ?>
        <?php if (!is_array($leagues)): ?>
            <option value="<?php echo $sport; ?>"><?php echo $leagues; ?></option>
        <?php else: ?>
            <optgroup label="<?php echo $sport; ?>">
                <?php foreach ($leagues as $league_id => $league_name): ?>
                    <option value="<?php echo $league_id; ?>"><?php echo $league_name; ?></option>
                <?php endforeach; ?>
            </optgroup>
        <?php endif; ?>
    <?php endforeach; ?>
    </select>
<?php endif; ?>

