I have the following custom post types: books, documents, examples, guidebooks, onlineaids. They were generated by the following code:
/*-----------------------------------------------------------------------------------*/
/* CPT - Books */
/*-----------------------------------------------------------------------------------*/
function jeo_cpt_books() {
$labels = array(
'name' => _x( 'Books', 'post type general name' ),
'singular_name' => _x( 'Book', 'post type singular name' ),
'add_new' => _x( 'Add New', 'book' ),
'add_new_item' => __( 'Add New Book' ),
'edit_item' => __( 'Edit Book' ),
'new_item' => __( 'New Book' ),
'all_items' => __( 'All Books' ),
'view_item' => __( 'View Books' ),
'search_items' => __( 'Search Books' ),
'not_found' => __( 'No books found' ),
'not_found_in_trash' => __( 'No books found in the Trash' ),
'parent_item_colon' => '',
'menu_name' => 'Books'
);
$args = array(
'labels' => $labels,
'description' => 'Holds our books and book specific data',
'public' => true,
'menu_position' => 5,
'menu_icon' => get_bloginfo('template_directory') . '/images/icons/icon-book.png', // Icon Path
'taxonomies' => array('post_tag'), // Adds tags to cpt
'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments' ),
'has_archive' => true,
);
register_post_type( 'books', $args );
}
add_action( 'init', 'jeo_cpt_books' );
/* CPT - Books - Taxonomies */
function jeo_cpt_book_tax() {
$labels = array(
'name' => _x( 'Book Categories', 'taxonomy general name' ),
'singular_name' => _x( 'Book Category', 'taxonomy singular name' ),
'search_items' => __( 'Search Book Categories' ),
'all_items' => __( 'All Book Categories' ),
'parent_item' => __( 'Parent Book Category' ),
'parent_item_colon' => __( 'Parent Book Category:' ),
'edit_item' => __( 'Edit Book Category' ),
'update_item' => __( 'Update Book Category' ),
'add_new_item' => __( 'Add New Book Category' ),
'new_item_name' => __( 'New Book Category' ),
'menu_name' => __( 'Book Categories' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
);
register_taxonomy( 'book_category', 'books', $args );
}
add_action( 'init', 'jeo_cpt_book_tax', 0 );
(and so on)...
I am trying to loop through each CPT on a page-template for a different page and display them per "category" (which is a taxonomy). The following is the code I'm trying to use, with not much luck:
<?php $args = array(
'post_type' => 'books',
'book_category' => get_the_term_list( $post->ID, 'guidebook_category' ),
'posts_per_page' => -1,
'order' => 'ASC',
'orderby' => 'ID'
);
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) : ?>
<h2>Books:</h2>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<div class="resource_masterindex">
<?php the_excerpt(); ?>
</div>
<div class="clear"></div>
<?php endwhile; endif; ?>
<a href="#top" class="backtotop">Back to the top</a>
<?php wp_reset_postdata(); ?>
The above code seems to grab everything from the right CPT, but I want display ONLY the posts that are in the category called "Step2: Prepare" or "Step3: Find". Help is greatly appreciated.