Here is an example for you that I used for a message type like "FAQ":
get_header();
if(have_posts()) {
$args = array (
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => true,
);
$terms = get_terms( 'faq_levels', $args );
foreach ( $terms as $term ) {
echo $term->slug;
$post_args = array (
'post_type' => 'faq',
'faq_levels' => $term->name,
);
$query = new WP_Query( $post_args );
while ( $query->have_posts() ) {
$query->the_post(); ?>
and I created the message type as follows:
function post_type_faqs() {
register_post_type('faq', array(
'label'=>'FAQ',
'menu_icon' => '',
'labels'=>array(
'name'=>_x('FAQs', 'post type general name'),
'singular_name'=>_x('FAQ', 'post type singular name'),
'add_new'=>_x('Add New', 'faq'),
'add_new_item'=>__('Add New FAQ'),
'edit_item'=>__('Edit FAQ'),
'new_item'=>__('New FAQ'),
'view_item'=>__('View FAQ'),
'search_items'=>__('Search FAQs'),
'not_found'=>__('No faqs found'),
'not_found_in_trash'=>__('No faqs found in Trash'),
'parent_item_colon'=>''),
'public'=>true,
'publicly_queryable'=>true,
'show_ui'=>true,
'query_var'=>true,
'rewrite'=>false,
'capability_type'=>'post',
'supports'=>array('title','thumbnail','post-formats'),
'taxonomies'=>array('post_tag','faq_category'),
'slug'=>'faq',
'hierarchical'=>false,
'menu_position'=>6,
'show_in_nav_menus'=> true,
'has_archive' => true,
'can_export' => true,
'register_meta_box_cb' => 'faq_add_meta_boxes'
));
}
add_action('init', 'post_type_faqs');
function faq_category() {
$labels = array(
'name' => _x( 'Categories', 'Taxonomy General Name', 'dc' ),
'singular_name' => _x( 'Category', 'Taxonomy Singular Name', 'dc' ),
'menu_name' => __( 'Categories', 'dc' ),
'all_items' => __( 'All Categories', 'dc' ),
'parent_item' => __( 'Parent Category', 'dc' ),
'parent_item_colon' => __( 'Parent Category:', 'dc' ),
'new_item_name' => __( 'New Category', 'dc' ),
'add_new_item' => __( 'Add New Category', 'dc' ),
'edit_item' => __( 'Edit Category', 'dc' ),
'update_item' => __( 'Update Category', 'dc' ),
'separate_items_with_commas' => __( 'Separate categories with commas', 'dc' ),
'search_items' => __( 'Search Categories', 'dc' ),
'add_or_remove_items' => __( 'Add or remove categories', 'dc' ),
'choose_from_most_used' => __( 'Choose from the most used categories', 'dc' ),
'not_found' => __( 'Not Found', 'dc' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => true,
'sort_column' => 'menu_order',
);
register_taxonomy( 'faq_category', array( 'faq' ), $args );
}
add_action( 'init', 'faq_category', 0 );