I have following query to select posts by my custom post-type. This works fine while being on the frontpage (the snippet is included in the sidebar). As soon it gets executed on a category page the post_type
attribute is ignored and posts of the type "post" are returned. I guess this has to do with multiple loops but I have also tried to call wp_reset_postdata();
and wp_reset_query();
before and after.
$customPosts = new WP_Query( array(
'post_type' => 'mycustomtype',
'posts_per_page' => 12,
'orderby' => 'date',
'order' => 'DESC',
'post_status' => 'publish'
));
while ( $customPosts->have_posts() ) : $customPosts->the_post();
$thumbnailUrl = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), "thumbnail");
if ( !empty($thumbnailUrl)) {
/* echo result */
}
endwhile;
'get_posts'
that function suppress filters as default, so 'posts_where' filters aren't taken into account. So my guess is there is a filter on'pre_get_posts'
that not check for$query->is_main_query()
.