<?php
/**
 * Template Name: Faq Page
 */

get_header();
$extraQueryParams = [];
$tIds = getFaaTaxonomyIds();
if ($tIds !== false) {
    if (count($tIds) == 0) {
        $terms = [];
    } else {
        $terms = get_terms( [
            'taxonomy' => 'fac_category_type',
            'hide_empty' => true,
            'orderby'    => 'term_order',
            'include' => $tIds
        ]);
    }
} else {
    $terms = get_terms( [
        'taxonomy' => 'fac_category_type',
        'hide_empty' => true,
        'orderby'    => 'term_order',
    ]);
}




?>

<div class="main-page">
    <div class="faq-search">
        <div class="cont">
            <form method="POST" id="search-form" action="/faq-page">
                <input type="text" placeholder="What do you need help with?" name="search_text" value="<?= enableSearchQuery()?$_POST['search_text']:''?>">
                <a href="#" class="start-search">
                    <span class="icon-search"></span>
                </a>
            </form>
        </div>
    </div>
    <div class="breadcrumbs">
        <div class="cont">
            <ol class="breadcrumb">
                <li><a href="#">Home</a></li>
                <li class="active">FAQ</li>
            </ol>
        </div>
    </div>


    <div class="faq-list">
        <div class="cont">
            <?php foreach ($terms as $term):?>
            <div class="front-accordion">
                <div class="fa-head">
                    <a class="collapse-link" data-toggle="collapse" href="#fc-<?= $term->term_id ?>" aria-expanded="true"><span class="icon-caret"></span> <?= $term->name?></a>
                </div>
                <div class="fa-body collapse in" id="fc-<?= $term->term_id ?>">
                    <div class="fa-cont">
                        <?php
                        $posts = getFaqPosts(['post_type' => 'fac_category_answer',
                            'numberposts' => -1,
                            'suppress_filters' => false,
                            'tax_query' => [
                                [
                                    'taxonomy' => 'fac_category_type',
                                    'field' => 'id',
                                    'terms' => $term->term_id,
                                    'include_children' => false
                                ]
                            ]
                        ]);
                        foreach ($posts as $post) {

                            echo '
                                <div class="faq-question">
                                    <a href="'.get_permalink($post).'">'.$post->post_name.'</a>
                                </div>
                            ';
                        }

                        ?>
                    </div>
                </div>
            </div>
            <?php endforeach; ?>
        </div>
    </div>
</div>
<?php
get_footer();


