I just recreated your setup.
I created a post-type called “supplier-showcase”.
I created a taxonomy called “supplier-category”, and added a term with the slug “supplier-cakes”.
Added some posts with and without the term “supplier-cakes”.
Than I copied your code, inserted it in a simple page template, fixed the things I already mentioned, and reindented the code (for my readability).
This is working without any problems:
<div class="gridcontainer">
<?php
// Grid Parameters
$counter = 1; // Start the counter
$grids = 5; // Grids per row
$titlelength = 20; // Length of the post titles shown below the thumbnails
// The Query
$args = array(
'post_type' => 'supplier-showcase',
'posts_per_page' => 3,
'tax_query' => array(
array(
'taxonomy' => 'supplier-category',
'field' => 'slug',
'terms' => 'supplier-cakes'
),
),
);
$query = new WP_Query($args);
// The Loop
if ($query->have_posts()) :
while ( $query->have_posts() ) : $query->the_post();
// Show all columns except the right hand side column
if($counter != $grids) : ?>
<div class="griditemleft">
<?php if ( has_post_thumbnail() ) : ?>
<div class="postimage">
<a href="#<?php the_ID(); ?>" ><img src="<?php the_post_thumbnail_url(); ?>" /></a>
</div><!-- .postimage -->
<?php endif; ?>
<h2 class="postimage-title">
title is <?php the_title(); ?>
</h2>
<div id="<?php the_ID(); ?>" class="lightbox-by-id lightbox-content lightbox-white mfp-hide" style="max-width:600px ;padding:20px">
<img src="<?php the_post_thumbnail_url(); ?>" width="200px" height="200px" /> <br>
</div>
</div><!-- .griditemleft -->
<?php
// Show the right hand side column
elseif($counter == $grids) : ?>
<div class="griditemright">
<?php if ( has_post_thumbnail() ) : ?>
<div class="postimage">
<a href="#<?php the_ID(); ?>" ><img src="<?php the_post_thumbnail_url(); ?>" /></a>
</div><!-- .postimage -->
<?php endif; ?>
<h2 class="postimage-title">
title is <?php the_title(); ?>
</h2>
<div id="<?php the_ID(); ?>" class="lightbox-by-id lightbox-content lightbox-white mfp-hide" style="max-width:600px ;padding:20px">
<img src="<?php the_post_thumbnail_url(); ?>" width="200px" height="200px" /> <br>
</div>
</div><!-- .griditemright -->
<div class="clear"></div>
<?php $counter = 0;
endif;
$counter++;
endwhile;
endif;
wp_reset_postdata(); ?>
</div><!-- .gridcontainer -->
You also have some problematic if statements in your code like this (see where if starts and ends), which doesnt make sense:
<div class="postimage">
<?php if ( has_post_thumbnail() ) : ?>
<a href="#<?php the_ID(); ?>" ><img src="<?php the_post_thumbnail_url(); ?>" /></a>
</div><!-- .postimage -->
<h2 class="postimage-title">
title is <?php the_title(); ?>
</h2>
<?php endif; ?>
You said in your comment that if you remove the tax_query to just show all custom posts, than this is working. So look into the tax_query to see if you got your slugs right. You can also try using term ID´s instead of slugs.