I have a custom post type named resources
. Resources use a custom taxonomy resource
.
When I originally planned my WordPress website, I assumed that I would only ever need to use the resource taxonomy for resources. Well, it turns out that I write posts that are resources that don't need to use the custom post type that resources uses. (Resources template is used for files, etc).
The code below is how I am displaying all of my Resource posts. I get a header for each category once and then list the posts that are in that category. I want all the resources on a single page, nicely organized. The problem is that I need to include posts in the list as well... I've tried editing this code and its not working.
<?php
$custom_terms = get_terms('resource');
foreach($custom_terms as $custom_term) {
wp_reset_query();
$args = array('post_type' => 'resources',
'tax_query' => array(
array(
'taxonomy' => 'resource',
'field' => 'slug',
'terms' => $custom_term->slug,
),
),
);
$loop = new WP_Query($args);
if($loop->have_posts()) {
echo '<h2>'.$custom_term->name.'</h2><ul>';
while($loop->have_posts()) : $loop->the_post();
echo '<li><a href="'.get_permalink().'">'.get_the_title().'</a></li>';
endwhile;
echo '</ul>';
}
}
?>
I'm assuming that whatever I've been doing has been missing something really easy, but I can't figure it out.