I am trying to filter my custom post type posts in their 3 categories. The post type "fodrimu" has local places for eating, drinking or music but I tried multiple ways already but I'm unable to filter them properly.
first way:
menu that links to the category: music of fodrimu posts. this filters my posts but does this through index.php where each regular post type has extra buttons for liking and sharing. I've tried to include following templates but it keeps showing index.php
- archive-fodrimu.php
- category-fodrimu.php
- fodrimu-category.php
loop:
<?php
if (have_posts()) :
while (have_posts()) :
the_post();
?>
<div class="contentBlock item article">
<div class="headImageContainer">
<?php
$image = get_field('thumbnail');
?>
<a href="<?php the_field('link_website') ?>" target="_blank">
<div class="headImage" style='background-image:url("<?php echo $image['url']; ?>");'></div>
</a>
</div>
<div class="intro">
<h2><?php the_title() ?> </h2>
<p class="excerpt"><?php the_field('inleiding') ?></p>
</div>
</div>
<?php
endwhile;
endif;
?>
taxonomy registration:
function taxonomies_fodrimu(){
$labels = array(
'name' => _x('Fodrimu Categories', 'taxonomy general name'),
'singular_name' => _x('Fodrimu Category', 'taxonomy singular name'),
'search_items' => __('Search Fodrimu Categories'),
'all_items' => __('All Fodrimu Categories'),
'parent_item' => __('Parent Fodrimu Category'),
'parent_item_colon' => __('Parent Fodrimu Category:'),
'edit_item' => __('Edit Fodrimu Category'),
'update_item' => __('Update Fodrimu Category'),
'add_new_item' => __('Add New Fodrimu Category'),
'new_item_name' => __('New Fodrimu Category'),
'menu_name' => __('Fodrimu Categories')
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
);
register_taxonomy('fodrimu_category', 'fodrimu', $args);}
add_action('init', 'taxonomies_fodrimu', 0);
second way:
In my second approach I made custom templates with the names drinks, food and music and in my navigation i linked to pages where i gave the template name.
I tried to just retrieve the fudrimu posts with the needed category but It ignores the categories and just shows all fudrimu posts. i've tried following category (declarations?):
- 'cat' -> 'music'
- 'post_type_cat' -> 'music'
- 'category' -> 'music'
wp_query :
$args = array(
'post_type' => 'fodrimu',
'cat' => 'music');
$wp_query = new WP_Query($args);