0

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.

1 Answer 1

0

If you'd like to include the post post type, it needs to be added to the post_type parameter for WP_Query:

        $args = array('post_type' => array( 'post', 'resources' ),
            'tax_query' => array(
                array(
                    'taxonomy' => 'resource',
                    'field' => 'slug',
                    'terms' => $custom_term->slug,
                ),
            ),
         );
1
  • I swear I tried that and it didn't work. I'll try and run it again and see if it pans out.
    – jonbon
    Oct 8, 2016 at 0:56

Your Answer

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

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