Can I use this snippet to retrieve posts from a custom taxonomy in a custom post type?

<?php $sermon_series = new WP_Query( array('series' => 'type')); ?>

<?php while ($sermon_series->have_posts()) : $sermon_series->the_post(); ?>

<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>

<?php endwhile; ?>

It displays regular posts now, but I need it to display posts from a custom post type called "Sermons" in my wordpress.

1 Answer 1


Reference: WordPress Codex — Custom Taxonomies > Querying by taxonomy

Creating a taxonomy generally automatically creates a special query variable using WP_Query class, which we can use to retrieve posts based on. For example, to pull a list of posts that have "Bob" as a "person" taxonomy in them, we will use:

$query = new WP_Query( array( 'person' => 'bob' ) );

or, for more complex argument:

$args = array(
    'tax_query' => array(
            'taxonomy' => 'person',
            'field' => 'slug',
            'terms' => 'bob'
$query = new WP_Query( $args );

What's above is quoted from the document I linked far above, and I think it's very very relevant/close to what you are doing.


<?php query_posts(array( 'post_type' => 'sermon', 'sermon_series' => $sermon_series )); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

<div class="post">
    <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    <small><?php the_time('F jS, Y') ?></small>

<?php endwhile; ?>
<?php endif; ?>
  • Thanks for the reply! I ended up finally figuring it out. Commented Jul 17, 2012 at 4:00
  • @ftntravis I took the liberty to edit your question, take the answer and add it in mine. (Answers are not supposed to be in questions.) If you want I can edit my answer and remove it, so that you can add your own answer. :)
    – its_me
    Commented Jul 17, 2012 at 11:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.