I'm having issues running a query inside of my functions.php file. I have quite an extensive function which returns a set of posts based upon a number of set parameters.
I need to now run a loop inside of the functions loop to give me another result.
If i do this in a normal page it looks like this and works fine:
<div class="brief">
<a href="<?php the_permalink(); ?>"><?php the_title() ?></a>
<?php
$terms = get_the_terms( $post->ID, 'supplier-tax');
foreach ( $terms as $term ) {
$termID[] = $term->term_id;
}
$the_query = new WP_Query( array(
'post_type' => 'supplier',
'tax_query' => array(
array(
'taxonomy' => 'supplier-tax',
'terms' => $termID,
)
),
) );
while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<p class="suppy"><?php the_title(); ?></p>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<p class="hide-for-small-only"><?php echo get_the_excerpt(); ?></p>
<a class="more-btn" href="<?php the_permalink(); ?>">More</a>
</div>
</div>
However if i want to output this in the $out
section of my function, it does not work, here is my latest attempt:
$out .= '<div class="small-12 large-6 columns end thumb under" data-equalizer-watch>
<div id="case">
<div class="th" id="element" style="background-image: url('.get_field("product_image", false, true).')">
<a class="fill-div" href="'. get_permalink($post->ID) .'"></a>
</div>
</div>
<div class="brief">
<a href="'. get_permalink($post->ID) .'">'.get_the_title().'</a>
'$terms = get_the_terms( $post->ID, 'supplier-tax');
foreach ( $terms as $term ) {
$termID[] = $term->term_id;
}
$the_query = new WP_Query( array(
'post_type' => 'supplier',
'tax_query' => array(
array(
'taxonomy' => 'supplier-tax',
'terms' => $termID,
)
),
) );
while ( $the_query->have_posts() ) : $the_query->the_post();'
<p class="suppy">'.get_the_title().'</p>
'endwhile;'
'wp_reset_postdata();'
<p class="hide-for-small-only">'.get_the_excerpt().'</p>
<a class="more-btn" href="'. get_permalink($post->ID) .'">More</a>
</div>
</div>';
According to debug I have unxepected $terms
which is the first line of the query on line 9 of that code, however i have no idea how else i would need to add the $terms can anyone help?