Support » Plugins » How to query post in the current custom taxonomy?

  • Hello guys…

    I have a custom post type called “lessons”, and a custom taxonomy called “courses”, I want to display in the sidebar the list (with links) of the posts in the current “courses” taxonomy. If the current post is in the course “music” I want to display all posts (lessons) in that course, if the course is “Cooking” I want to display all posts (lessons) in that course.

    There’s a solution I’ve tried and works perfectly with the get_the_category() function, but I need it to work with my own taxonomy (“courses”).

    Here’s the code for query post in the current category that works well (I need something like this, but with my custom taxonomy):

    <h4>Lessons on this category:</h4>
    			<ul>
    				<?php
    				global $post;
    				$category = get_the_category($post->ID);
    				$category = $category[0]->cat_ID;
    				$myposts = get_posts(array('post_type' => 'lessons', 'numberposts' => 12, 'offset' => 0, 'category__in' => array($category), 'post_status'=>'publish', 'order' => 'ASC',));
    				foreach($myposts as $post) :
    				setup_postdata($post);
    				?>
    				<li>
    				<a href="<?php the_permalink(); ?>">
    				<?php the_title(); ?></a>
    				</li>
    				<?php endforeach; ?>
    				<?php wp_reset_query(); ?>
    			</ul>
  • The topic ‘How to query post in the current custom taxonomy?’ is closed to new replies.