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.
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:
or, for more complex argument:
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.
Solution: