• I have hit a wall with this one and I can’t seem to figure it out…I’m starting to lose hope!
    I could really use some help on this one.

    Here is what I’m trying to do:
    I’m trying to display 1 post from each category, but only if that post has a certain custom taxonomy.

    For example…

    I’d like to display a post called “Come Together” in the category “Beatles”. BUT I only want that post to display IF it has the custom taxonomy labeled “Abbey Road”

    And I’d like it limited to only one post per category.

    I believe this is possible, I just can’t seem to make it work right.

    Some help would be really, really appreciated.

    Thanks!

    Here is my code (which is not working)

    <?php
    $categories=get_categories($all_categories);
    foreach($categories as $category) {
    $taxonomy = 'session';
    $param_type = 'session';
    $include_terms = 21; //term ids to include
    $post_args=array(
    'showposts' => 1, // you can fetch number of articles from each category
    'category__in' => array($category->term_id),
    'caller_get_posts'=>1,
    'include' => $include_terms,
    );
    $posts=get_posts($taxonomy,$post_args);
    if ($posts) {
    
    foreach($posts as $post) {
    setup_postdata($post); ?>
    <div class="twentyten-artist-post">
    	<div class="twentyten-artist-post-image">
    		<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_post_thumbnail(array(20,20), array ('class' => 'alignleft')); ?>
    	</div>
    	<br><div class="twentyten-artist-post-title">
    		<?php
    		$category = get_the_category();
    		echo $category[0]->cat_name;
    		?>
    		<?php
    		$category = get_the_category();
    		echo "(", $category[0]->category_count, ")";
    		?>
    		</a>
    	</div>
    	<div class="clear"></div>
     </div>
     <?php
     } // foreach($posts
     } // if ($posts
     } // foreach($categories
    ?>

  • The topic ‘Display 1 post (with a custom Taxonomy) from each category’ is closed to new replies.