I've created a custom post type with categories and sub categories, what I need to do is list out the post titles and images for a given sub-category or category in a page template.
I've got as far as getting the all the listed items in the custom post type, but I'm unsure how to go further... any help appreciated.
<?php
$args = array( 'post_type' => 'portfolio', 'posts_per_page' => 10 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
the_title();
echo '<div class="entry-content">';
the_content();
echo '</div>';
endwhile;
?>
The function that creates the custom post type and taxonomy looks like this:-
<?php
// CUSTOM POST TYPE 1
add_action('init', 'portfolio_register');
function portfolio_register() {
$args = array(
'label' => __('Portfolio'),
'singular_label' => __('Portfolio'),
'public' => true,
'show_ui' => true,
'capability_type' => 'post',
'hierarchical' => false,
'rewrite' => true,
'supports' => array('title', 'editor', 'thumbnail')
);
register_taxonomy("galleries", array("portfolio"), array(
"hierarchical" => true,
"label" => "Galleries",
"singular_label" => "Galleries",
"rewrite" => true)
);
register_post_type( 'portfolio' , $args );
}
add_action("admin_init", "admin_init");
add_action('save_post', 'save_portfolio_options');
add_action('save_post', 'save_portfolio_single_options');
function admin_init(){
add_meta_box("gallerymeta", "Gallery Options", "portfolio_meta_options", "portfolio", "normal", "low");
add_meta_box("portfoliometa", "Portfolio Item Options", "portfolio_single_meta_options", "portfolio", "side", "low");
}
function portfolio_meta_options(){
global $post;
$custom = get_post_custom($post->ID);
$excerpt = $custom["excerpt"][0];
$info = $custom["info"][0];
$linkto = $custom["linkto"][0];
?>
register_post_type
has aregister_meta_box_cb
arg that accepts a callback function to register metaboxes applicable to that type(so you don't need to register then on the init action, which would be the incorrect action to register them on anyway)..