Custom Post Type: How to display all of same taxonomy?

Isn’t there a permalink structure that will essentially list out all categories of a certain post type?

function create_faqs_post_type() {
    register_post_type( 'faqs',
        array(
            'labels' => array(
                'name' => __( 'FAQs' ),
                'singular_name' => __( 'FAQ' )
            ),
        'public' => true,
        'menu_position' => 5,
        'rewrite' => array('slug' => 'the-faqs')
        )
    );
}
add_action( 'init', 'create_faqs_post_type' );

function create_faq_taxonomy() {
    register_taxonomy(
        'faqs_categories',
        'faqs',
        array(
            'hierarchical' => true,
            'label' => 'FAQs Categories',
            'query_var' => true
        )
    );
}
add_action( 'init', 'create_faq_taxonomy' );

This is the code I’ve using to register the custom post type faqs and then register a taxonomy for it.

Read More

Isn’t there a permalink structure that will essentially automatically list out all faqs of a certain taxonomy? Or do I need to create a custom template and query it specifically?

Related posts

Leave a Reply

2 comments

  1. @dcolumbus

    You can do a permalink rewrite when you register the taxonomy using the following:

    ‘rewrite’ => array( ‘slug’ => ‘faqcategories’, ‘with_front’ => false ),

    Then site.com/faqcategories should pull them and site.com/faqcategories/easy should get them for you for the ‘easy’ term.

    If I’m understanding you correctly.

  2. You can use something like this:

    <?php
    $catArgs = array(
            'taxonomy'=>'faqs_categories'
            // post_type isn't a valid argument, no matter how you use it.
            );
    $categories = get_categories('taxonomy=faqs_categories&post_type=faqs'); ?>
    <?php foreach ($categories as $category) : ?>
      <div class="faqs-cat"><?php echo $category->name; ?></div>
        <?php
        $postArgs = array(
            'orderby' => 'title',
            'order' => 'ASC',
            'post_type'=>'faqs',
            'cat'=>$category->cat_ID,
            'tax_query' => array(
                    array(
                        'taxonomy' => 'faqs_categories'
                    )
                )
            );
         query_posts($postArgs) ?>
        <ul>
             <?php while(have_posts()): the_post(); ?>
            <li><a><?php the_title() ?></a></li>
             <?php endwhile; ?>
        </ul>
    <?php endforeach; ?>
    <?php wp_reset_query();
    

    Edited but original source here. Good luck, I hope this helps.