Eerst maken we de post type aan en de custom taxonomy
register_post_type('faq',
array(
'labels' => array(
'name' => __('FAQ', 'wbmz'),
'singular_name' => __('FAQ', 'wbmz'),
'add_new' => __('Nieuwe vraag', 'wbmz'),
'add_new_item' => __('Voeg nieuwe vraag toe', 'wbmz'),
'edit' => __('Wijzig', 'wbmz'),
'edit_item' => __('Wijzig vraag', 'wbmz'),
'new_item' => __('Nieuwe vraag', 'wbmz'),
'view' => __('Bekijk vraag', 'wbmz'),
'view_item' => __('Bekijk vraag', 'wbmz'),
'search_items' => __('Zoek vragen', 'wbmz'),
'not_found' => __('Geen vragen gevonden', 'wbmz'),
'not_found_in_trash' => __('Geen vragen gevonden in de prullenbak', 'wbmz')
),
'public' => true,
'hierarchical' => true,
'has_archive' => true,
'show_in_rest' => true,
'menu_icon' => 'dashicons-editor-help',
"rewrite" => array( 'slug' => false, 'with_front' => false ),
'supports' => array(
'title',
'editor',
'excerpt',
'thumbnail'
),
'can_export' => true
));
register_taxonomy("faq_cat",
array("faq"),
array(
"hierarchical" => true,
"label" => "FAQ Categorieen",
"show_in_rest" => true,
"singular_label" => "FAQ categorie",
"rewrite" => array( 'slug' => 'faqcat', 'hierarchical' => false ),
"show_admin_column" => true
));
Daarna zetten we dit netjes in de template en groeperen we per categorie
<?php
$terms = get_terms('faq_cat'); ?>
<?php if($terms): ?>
<div class="container-fluid fq">
<div class="container">
<?php foreach( $terms as $term ): ?>
<div class="row">
<div class="col-12 col-md-4 ttl">
<h2>Vragen over <?php echo $term->name; ?>:</h2>
</div>
<div class="col-12 col-md-8">
<?php
$posts = get_posts(array(
'post_type' => 'faq',
'taxonomy' => $term->taxonomy,
'term' => $term->slug,
'nopaging' => true, // to show all posts in this taxonomy, could also use 'numberposts' => -1 instead
));
foreach($posts as $post): // begin cycle through posts of this taxonmy
setup_postdata($post); //set up post data for use in the loop (enables the_title(), etc without specifying a post ID)
?>
<div class="row">
<div class="col-1 col-sm-2 col-md-1 cntr grybg"><i class="fas fa-question-circle"></i></div>
<div class="col-10 grybg">
<h3><?php the_title(); ?></h3>
<p><?php the_excerpt();?></p>
<a href="<?php the_permalink(); ?>">Lees verder</a>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
<?php endif; ?>
#acf #custom taxonomy #faq #template