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;
Have you tried using get_posts() instead?
This will resolve your issue, I was having the same problem, when I put this it worked perfectly.