Support » Plugins » Hacks » Get all posts from custom taxonomy

  • add_action( 'init', 'custom_gallery_post_type' );
    function custom_gallery_post_type() {
        register_post_type( 'custom_gallery',
                'labels' => array(
                    'name' => __( 'Gallery', 'custum_gallery' ),
                    'singular_name' => __( 'Gallery Item', 'custum_gallery' ),
                'has_archive' => true,
                'hierarchical' => true,
                'public' => true,
                'rewrite' => array( 'slug' => 'custum_gallery' ),
    			'taxonomies' => array('custom_gallery_category'),
    			'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' )
    	register_taxonomy('custom_gallery_category', 'custom_gallery',
    			'hierarchical' => true,
    			'query_var' => true,
    			'rewrite' => true,
                'has_archive' => true,
                'hierarchical' => true,
                'public' => true
    function customgallery( $atts, $content = null ) {
    	$content='<ul class="gallery_menu">';
    	$_categories = get_categories('taxonomy=custom_gallery_category');
    	foreach ($_categories as $_cat){
    			<li class="'.$_cat->name.'" >
    				<a href="'.get_term_link( $_cat->slug, 'custom_gallery_category' ).'" title="'.$_cat->name.'">'.$_cat->name.'</a>
    		<div style="clear:both;"></div>
    		<ul class="gallery_item">'; 
    	$_item = new WP_Query(array('post_type' => 'custom_gallery', 'posts_per_page' => '-1'));
    		while ($_item->have_posts()) : $_item->the_post();
    		$content.='<li><a href="'.get_permalink().'" rel="bookmark" title="'.get_the_title().'"><img src="'.wp_get_attachment_image_src(get_post_thumbnail_id($_item->ID),'thumbnail')[0].'"></a>';
    		$content.='<a class="gallery_title" href="'.get_permalink().'" rel="bookmark" title="'.get_the_title().'">'.get_the_title().'</a></li>';
    		$terms = get_terms('custom_gallery_category');
    	return $content.'</ul>'.'<div style="clear:both;"></div>';
    add_shortcode('customgallery', 'customgallery');

    its working good with any theme which supports featured image.
    i can get posts for sub-categories on index.php
    i can get single posts on single.php
    I want to get all taxonomy posts without using taxonomy.php or any external template. So is it possible to get all custom taxonomy posts on index.php?

    Gives the result on index.php.
    I want to dosomething like that
    wordpress/?custom_gallery_category=is there a tag for this like ‘ALL’

  • The topic ‘Get all posts from custom taxonomy’ is closed to new replies.