I have a Custom Post Type called "book" and a custom taxonomy for this CPT called "books". One term's slug of this taxonomy is "accepting-yourself". Here's the code of the "accepting-yourself" archive page (URL: my_site/books/accepting-yourself/):
if ( have_posts() ) :
while ( have_posts() ) : the_post();
echo get_the_title();
endwhile;
endif;
This should return all the "book" posts in custom taxonomy "books", that's 8 posts. Instead it returns only one.
Just in case here's the code defining my custom post type and custon taxonomy:
/*------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
CUSTOM POST TYPE : BOOK
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
function my_custom_post_book() {
$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 Book' ),
'view_item' => __( 'View Book' ),
'search_items' => __( 'Search Book' ),
'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 specific data',
'public' => true,
'menu_position' => 4,
'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments', 'custom-fields'),
'has_archive' => true,
);
register_post_type( 'book', $args );
}
add_action( 'init', 'my_custom_post_book' );
function my_updated_messages_book( $messages ) {
global $post, $post_ID;
$messages['book'] = array(
0 => '',
1 => sprintf( __('Book updated. <a href="%s">View book</a>'), esc_url( get_permalink($post_ID) ) ),
2 => __('Custom field updated.'),
3 => __('Custom field deleted.'),
4 => __('Book updated.'),
5 => isset($_GET['revision']) ? sprintf( __('Book restored to revision from %s'), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
6 => sprintf( __('Book published. <a href="%s">View book</a>'), esc_url( get_permalink($post_ID) ) ),
7 => __('Book saved.'),
8 => sprintf( __('Book submitted. <a target="_blank" href="%s">Preview book</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
9 => sprintf( __('Book scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview book</a>'), date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ),
10 => sprintf( __('Book draft updated. <a target="_blank" href="%s">Preview book</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
);
return $messages;
}
add_filter( 'post_updated_messages', 'my_updated_messages_book' );
/*------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
CUSTOM BOOK TAXONOMY
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
$labels = array(
'name' => 'Books',
'singular_name' => 'Book',
'search_items' => 'Search Books',
'popular_items' => 'Popular Books',
'all_items' => 'All Books',
'parent_item' => 'Parent Book',
'edit_item' => 'Edit Book',
'update_item' => 'Update Book',
'add_new_item' => 'Add New Book',
'new_item_name' => 'New Book',
'separate_items_with_commas' => 'Separate Books with commas',
'add_or_remove_items' => 'Add or remove Books',
'choose_from_most_used' => 'Choose from most used Books'
);
$args = array(
'label' => 'Books',
'labels' => $labels,
'public' => true,
'hierarchical' => true,
'show_ui' => true,
'show_in_nav_menus' => true,
'args' => array( 'orderby' => 'term_order' ),
'rewrite' => array( 'slug' => 'books', 'with_front' => false ),
'query_var' => true
);
register_taxonomy( 'books', 'book', $args );