I’m trying to get the term name of the current post from the taxonomy floorplanarea.
I want to display the term name and then output all posts under the term
Could anyone help me?
<?php
$floorplan_area = get_sub_field('floorplan_area');
if ($floorplan_area) {
if (!is_array($floorplan_area)) {
$floorplan_area = array($floorplan_area);
}
$args = array(
'post_type' => 'floorplan',
'posts_per_page' => -1,
'orderby' => 'post_title',
'order' => 'ASC',
'tax_query' => array(
array(
'taxonomy' => 'floorplanarea',
'terms' => $floorplan_area,
),
),
);
$area_query = new WP_Query($args);
if ($area_query->have_posts()) {?>
/*Title of term name to go here*/
<div>
<?php
while($area_query->have_posts()) {
$area_query->the_post(); ?>
<h1><?php echo the_title(); ?></h1>
<?php } ?>
</div>
<?php
}
wp_reset_postdata();
}
?>
2
Answers
Found the solution
A WP_Term object
As it’s an object you need to use a foreach loop