| 1 |
<?php |
| 2 |
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- view template receives variables via extract(); prefixing is impractical. |
| 3 |
|
| 4 |
if ( ! defined( 'ABSPATH' ) ) { |
| 5 |
exit; |
| 6 |
} |
| 7 |
$faq_taxonomy = isset( $term->taxonomy ) ? $term->taxonomy : 'betterdocs_faq_category'; |
| 8 |
$faqs = betterdocs()->query->get_faq_by_term( $term->term_id, $faq_taxonomy ); |
| 9 |
|
| 10 |
if ( $faqs->have_posts() ) { |
| 11 |
echo '<ul class="betterdocs-faq-list">'; |
| 12 |
|
| 13 |
$faq_markup = ''; |
| 14 |
while ( $faqs->have_posts() ) : |
| 15 |
$faqs->the_post(); |
| 16 |
$faq_toggle = (bool)get_post_meta(get_the_ID(), 'faq_open_by_default', true); |
| 17 |
echo '<li>'; |
| 18 |
echo '<div class="betterdocs-faq-group'.($faq_toggle ? ' active' : '').'">'; |
| 19 |
$view_object->get( 'shortcode-parts/faq-title', [ |
| 20 |
'faq_toggle' => $faq_toggle |
| 21 |
] ); |
| 22 |
$view_object->get( 'shortcode-parts/faq-content', [ |
| 23 |
'faq_toggle' => $faq_toggle |
| 24 |
] ); |
| 25 |
echo '</div>'; |
| 26 |
echo '</li>'; |
| 27 |
|
| 28 |
if ( $faq_schema ) { |
| 29 |
$faq_json = [ |
| 30 |
'@type' => 'Question', |
| 31 |
'name' => get_the_title(), |
| 32 |
'acceptedAnswer' => [ |
| 33 |
'@type' => 'Answer', |
| 34 |
'text' => get_the_content() |
| 35 |
] |
| 36 |
]; |
| 37 |
$GLOBALS['betterdocs_faq_schema_main_entity'][] = $faq_json; |
| 38 |
} |
| 39 |
endwhile; |
| 40 |
wp_reset_postdata(); |
| 41 |
wp_reset_postdata(); |
| 42 |
echo $faq_markup; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 43 |
echo '</ul>'; |
| 44 |
} else { |
| 45 |
echo '<p>' . esc_html__( 'Sorry, no FAQ matched your criteria.', 'betterdocs' ) . '</p>'; |
| 46 |
} |
| 47 |
|