Skip to main content
edited title
Link
Adrian
  • 31
  • 1
  • 4

Categories of custom taxonomy in filter menu don't show any posts

Source Link
Adrian
  • 31
  • 1
  • 4

Categories of custom taxonomy in filter menu don't show any posts

I want to display posts from categories of my custom taxonomy but realy don't know how to achieve this. I am using isotope filtering which works as expected with default post categories. I can click on a particular category and it shows all posts related to that category but it doesn't work with my custom taxonomy. I can see all sub-taxonomies (thanks to Rajeev Vyas) but when I am clicking on one of them - no posts are displayed. Can you please tell me what I am doing wrong?

This is the code from my functions.php:

add_action('init', 'portfolio_register');
function portfolio_register() {
     $labels = array(
        'name' => _x('My Portfolio', 'post type general name'),
        'singular_name' => _x('Portfolio Item', 'post type singular name'),
        'add_new' => _x('Add New', 'portfolio item'),
        'add_new_item' => __('Add New Portfolio Item'),
        'edit_item' => __('Edit Portfolio Item'),
        'new_item' => __('New Portfolio Item'),
        'view_item' => __('View Portfolio Item'),
        'search_items' => __('Search Portfolio'),
        'not_found' =>  __('Nothing found'),
        'not_found_in_trash' => __('Nothing found in Trash'),
        'parent_item_colon' => ''
    );
    $args = array(
        'labels' => $labels,
        'public' => true,
        'publicly_queryable' => true,
        'show_ui' => true,
        'query_var' => true,
        'menu_icon' => get_stylesheet_directory_uri() . '/images/portfolio-icon.png',
        'rewrite' => true,
        'capability_type' => 'post',
        'hierarchical' => false,
        'menu_position' => null,
        'supports' => array('title','editor','author','thumbnail','comments')
      ); 
    register_post_type( 'portfolio' , $args );
    flush_rewrite_rules();
}
// Custom taxonomy for Portfolio Categories (Galleries)
register_taxonomy('galleries', array('portfolio'), array('hierarchical' => true, 'label' => 'Galleries', 'singular_label' => 'Gallery', 'rewrite' => true, 'public' => true ));


And this code is from my loop.php which is my custom post type template:

 <?php /* Display filter options if homepage  */ ?>
<?php if(is_home()) { ?>
<div id="filtering-nav">
        <a href="#" class="filter-btn"><span>Filter</span></a>
        <ul>
                <li><a href="#all" class="all">All</a></li>
            <?php
            $args=array( 'orderby' => 'name', 'taxonomy'=>'galleries' );
            $categories=get_categories($args);
            foreach($categories as $category) {  ?>
                    <li><a href="#<?php echo $category->category_nicename; ?>" class="<?php echo $category->category_nicename; ?>"><?php echo $category->name; ?></a></li>
            <?php } ?>
        </ul>
        <div class="clearfix"></div>
</div>
<?php } ?>

<?php /* If this is the homepage, display all posts on one page  */ 
if(is_home() && get_option('show_all') && !is_search()) { query_posts('post_type=portfolio', 'posts_per_page=-1'); } ?>

<?php if (have_posts()) : ?>


Hope that my english doesn't hurt your eyes....