Just learning PHP. Wondering what I'm doing wrong here.
The aim is: if custom field in taxonomy term (in "shows" taxonomy) has data, show posts loop of taxonomy term in a custom post type ("blogs"). The field data has the name of the desired taxonomy term. My code is returning all the posts in the post type instead of my specified term. I was also convinced I limited the post count to 2, but that changed up on me for some reason and it's displaying infinite posts.
<?php
$news = get_field('news', $term);
if ( $news ) {
?>
<h2 class="showhead">News & Upcoming Shows</h2>
<?php
$custom_terms = get_terms('show-blogs');
foreach ( $custom_terms as $custom_term ) {
wp_reset_query();
$args = array(
'post_type' => 'blogs',
'posts_per_page' => 2,
'tax_query' => array(
array(
'taxonomy' => 'show-blogs',
'field' => $news,
'terms' => $custom_term->slug,
'posts_per_page' => 2,
),
),
);
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) {
while ( $loop->have_posts()) {
$loop->the_post();
?>
<table style="border:none;border: none;max-width: 50%;float: left;">
<tr>
<td rowspan="2" style="border:none;width: 113px;">
<?php the_post_thumbnail('thumbnail'); ?>
</td>
<td style="border:none;height: 45px;">
<?php the_title( sprintf( '<h3><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ),'</a></h3>' ); ?>
</td>
</tr>
<tr>
<td style="border:none"><?php the_excerpt();?></td>
</tr>
</table>
<?php
}
}
}
}
One thing I could do differently to make things easier is just call the "shows" term as it's the same as the "blogs" term which I need.
Any guidance is appreciated.