I am currently working on two sites that make extensive use of custom post types. For both we have a defined number of items (cpts) that fall under a particular bucket (categories).
One of the sites is for a design shop, so the cpts are websites, logos, business cards, etc. And the categories are all the clients (several hundred).
Since the number of categories is quite large and always changing, I need to use a category.php template to display the collected projects (cpts) for a particular client.
I also need my cpts to display in a certain order--so websites in the top section of the page, logos in the bottom section, for example.
I initially created mulitple loops using query_posts & wp_reset_query. This got the posts to show where I wanted, but pagination was screwed up and after reading more I realized using query_posts is a big no-no.
However, whenever I use WP_Query it seems to completely ingnore my post_type argument (and only post_type). For example:
<?php
$current_cat = get_query_var('cat');
$args1 = array(
'post_type' => 'event',
'cat' => $current_cat,
'offset' => 1
);
$query1 = new WP_Query( $args1 );
while ($query1->have_posts()) {
$query1->the_post();
echo '<li><a href="'.get_permalink( $post->ID).'">' . get_the_title() . '</a></li>';
} //endwhile;
?>
The other thing is that I am only seeing this issue on the category template. When I use a loop similar to the above on a page template it returns the correct post types. What am I missing here?
'post_type'
and remove'cat'
and'offset'
? Do you get the right results?pre_get_posts
filter to change the main query rather than adding a second? You should never usequery_posts
offset
is only there to return all minus the latest. I can remove that with no consequences. Just a vanilla main query on my category.php will return only posts of that category (as expected). But for some reason when I add arguments such as number or post type I now have to use$current_cat
or it returns all categories. Any idea why?