I have used a form with an Ajax action to pull post information through on submit.
It works a charm. However, I have used categories to separate the work into categories. One of which is the brand.
Within the page template the script I use works, but when used in the functions.php file. It doesn't pull the required results through.
I think it may be something to do with when the query to the post is triggered or how the add_action is set up.
Can someone please help me pull through the name of the category found within the ID of 31? When used in the functions.php.
Here is what I have written:
if( $query->have_posts() ) :
while( $query->have_posts() ): $query->the_post();
echo "<div class=\"portfolio-piece\" style=\"background-image: url(" . get_the_post_thumbnail_url() . ");\">";
echo "<a href=\"" . get_the_permalink() . "\" class=\"box-link\"></a>";
echo "<div class=\"portfolio-piece-hover\">";
echo "</div>";
echo "<div class=\"portfolio-piece-inner\">";
echo "<h5 class=\"portfolio-tags\">" . the_tags('', ' / ', '') . "</h5>";
echo "<h4 class=\"portfolio-title\">";
echo the_title();
echo "</h4>";
echo "<h4 class=\"portfolio-company\">";
$brands = wp_get_post_terms( $post->ID, 'category', array(
'orderby' => 'name',
'order' => 'DESC',
'parent' => 31
) );
foreach ( $brands as $brand ) {
echo $brand->name;
};
echo "</h4>";
echo "</div>";
echo "</div>";
endwhile;
wp_reset_postdata();
Where literally everything works but the portfolio-company / $brands = wp_get_post_terms part.
Thanks, Jason.