<?php
// Fungsi untuk menampilkan FAQ berdasarkan kategori di dalam FAQ Widget
function custom_category_faq_query($atts) {
$atts = shortcode_atts(
array(
'category' => '', // Kategori berdasarkan slug
'posts_per_page' => 5, // Jumlah post yang ditampilkan
),
$atts,
'custom_category_faq'
);
// Query untuk mengambil FAQ berdasarkan kategori
$args = array(
'post_type' => 'faq', // Ganti dengan CPT FAQ jika ada
'posts_per_page' => $atts['posts_per_page'],
'order' => 'ASC',
'category_name' => $atts['category'], // Kategori berdasarkan slug
);
$query = new WP_Query($args);
ob_start();
// Jika ada FAQ yang ditemukan
if ($query->have_posts()) :
echo '<div class="faq-content">';
while ($query->have_posts()) : $query->the_post();
echo '<div class="faq-item">';
echo '<h4>' . get_the_title() . '</h4>';
echo '<div>' . get_the_content() . '</div>';
echo '</div>';
endwhile;
echo '</div>';
else :
echo '<p>FAQ tidak tersedia.</p>';
endif;
wp_reset_postdata();
return ob_get_clean();
}
add_shortcode('custom_category_faq', 'custom_category_faq_query');