#StackBounty: #custom-post-types #custom-taxonomy #query How to filter custom taxonomy categories on archive?

Bounty: 50

I’m trying to modify my archive.php where I can select the categories and filter their records.

I can display the categories, detect if is a taxonomy page, but by selecting them, they are not filtering. what am I doing wrong?

When I select a category, it is showing all records, but without filtering.

archive.php

<?php }elseif(is_tax('downloads-category')){ ?>
<section id="conteudo">
    

Category Name

','

'); }?>
</div>
'downloads', 'taxonomy'=>'downloads-category', 'paged' => $paged ); $resultadoDownload = new WP_Query($infoDownload); if ($resultadoDownload->have_posts()) : while ($resultadoDownload->have_posts()) : $resultadoDownload->the_post(); $postThumb = (has_post_thumbnail()) ? get_the_post_thumbnail_url() : get_stylesheet_directory_uri()."/img/layout/sem-imagem.jpg"; $postThumb = ""; ?>

</div> <?php wp_reset_postdata(); endwhile; wpbs_pagination(); endif; ?> </div> </div> </div> </div> </section>

functions.php

function create_posttype() {
    register_post_type('downloads',
        array(
            'labels' => array(
                'name' => __('Downloads'),
                'featured_image' => __('Imagem Capa'),
                'singular_name' => __('Download'),
            ),
            'taxonomies'  => array('downloads-category'),
            'supports' => array(
                'title',
                'editor',
                'custom-fields',
                'thumbnail'
            ),
            'menu_icon'   => 'dashicons-category',
            'with_front' => true,
            'public' => true,
            'has_archive' => true,
            'rewrite' => array('slug' => 'downloads'),
        )
    );
    $labels = array(
        'name' => _x('Categorias', 'taxonomy general name'),
        'singular_name' => _x('Categoria', 'taxonomy singular name'),
        'search_items' =>  __('Procurar categoria'),
        'all_items' => __('Todos'),
        'edit_item' => __('Editar categoria'), 
        'update_item' => __('Editar categoria'),
        'add_new_item' => __('Adicionar categoria'),
        'new_item_name' => __('Nova categoria')
    );    
    register_taxonomy('downloads-category',array('downloads'), array(
        'hierarchical' => true,
        'labels' => $labels,
        'show_ui' => true,
        'query_var' => true,
        'show_in_nav_menus' => true,
        'rewrite' => array('slug' => 'categoria-de-downloads', 'with_front' => false),
    ));   
}
add_action('init', 'create_posttype');

Oh, and when i use tax_query, doesnt show anything…

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$infoDownload = array(
    'post_type' => 'downloads',
    'tax_query' => array(
        array(
            'taxonomy'=>'downloads-category',
            'field'    => 'slug'
        )
    ),
    'paged' => $paged
);
$resultadoDownload = new WP_Query($infoDownload); 
if ($resultadoDownload->have_posts()) :


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.