Custom Post Types, WP_Query & Categories
-
Hi,
I’m having an issue with custom post types and sorting through categorized posts using WP_Query.
The idea is that I want to populate different pages based on 5 custom post types I’ve created. They all use the same categories to organize the posts. I’d like to have the Category title display in an H2, then display all posts within that particular category.
This is what I have so far
<?php global $post; $slug = $post->post_name; $args = array( 'post_type'=> $slug ); $the_query = new WP_Query( $args ); $categories = get_categories(); foreach($categories as $category) { $myID = $category->ID; $myCat = $category->name; echo '<h2 class="clearfix">'; echo $myCat; echo '</h2>'; echo '<div class="row-fluid">'; $new_args = array( 'post_type'=> $slug, 'category_name '=> $myCat, 'cat' => $myID ); $my_query = new WP_Query( $new_args ); if ( $my_query->have_posts() ): while ( $my_query->have_posts() ) : $my_query->the_post(); echo '<div class="span2">'; $pdf_value = get_post_custom_values('item-location'); foreach ( $pdf_value as $key => $value ) : echo '<a href="'.$value.'" target="_blank"><div class="thumbnail">'; endforeach; the_post_thumbnail('full'); echo '</div><p>'; the_title(); echo '</p></a></div>'; endwhile; endif; wp_reset_postdata(); echo '</div>'; }; wp_reset_postdata(); ?>
What it does is display the category names, but then displays all the posts inside, regardless of categorization. The link to the demo page is
Any help would be greatly appreciated!
Devin
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Custom Post Types, WP_Query & Categories’ is closed to new replies.