admin管理员组文章数量:1122832
I have created a custom post (houses) and a custom taxonomy (houses_area). On each houses_area archive page, I want to see all the posts displayed by alphabetical order. I get stuck in calling the current taxonomy in the code. I want the code to adapt to each houses_area not just one in particular. I'm missing the way to call the current taxonomy (so the current houses_area) without naming it. I would like to add something like ''houses_area' => 'current one',' but I can't find what to put in place of 'current one'.
I hope this is clear... Thanks for any input!
Here is the code I use so far, which display all houses :
$args = array(
'post_type' => 'houses',
'posts_per_page' => -1,
'order' => 'ASC',
'orderby' => 'post_title',
);
$area_query = new WP_Query( $args );
if ( $area_query->have_posts() );
while ($area_query->have_posts()) : $area_query->the_post();
$photo = get_the_post_thumbnail();
$titre = get_the_title();
$link = get_permalink();
$address = get_field('address');
$size = "full"; ?>
<div class="container">
<div class="row">
<div class="vc_col-sm-3">
<div class="housesinfo">
<a href="<?php echo $link; ?>"><figure class="fighouse">
<?php echo $photo; ?>
<h2 class="titlehouse allhouses"><?php the_title(); ?></h2>
<div class="addresspointer">
<i class="qode_icon_font_awesome fa fa-map-marker qode-ili-icon-holder transparent" style="color: #2c4458;"></i>
<p><?php echo $address; ?></p>
</div>
</figure></a>
<p class="link-read-more allhouses qbutton"><a href="<?php echo $link; ?>">Read More</a></p>
</div>
</div>
</div>
</div>
<?php endwhile; ?>
I have created a custom post (houses) and a custom taxonomy (houses_area). On each houses_area archive page, I want to see all the posts displayed by alphabetical order. I get stuck in calling the current taxonomy in the code. I want the code to adapt to each houses_area not just one in particular. I'm missing the way to call the current taxonomy (so the current houses_area) without naming it. I would like to add something like ''houses_area' => 'current one',' but I can't find what to put in place of 'current one'.
I hope this is clear... Thanks for any input!
Here is the code I use so far, which display all houses :
$args = array(
'post_type' => 'houses',
'posts_per_page' => -1,
'order' => 'ASC',
'orderby' => 'post_title',
);
$area_query = new WP_Query( $args );
if ( $area_query->have_posts() );
while ($area_query->have_posts()) : $area_query->the_post();
$photo = get_the_post_thumbnail();
$titre = get_the_title();
$link = get_permalink();
$address = get_field('address');
$size = "full"; ?>
<div class="container">
<div class="row">
<div class="vc_col-sm-3">
<div class="housesinfo">
<a href="<?php echo $link; ?>"><figure class="fighouse">
<?php echo $photo; ?>
<h2 class="titlehouse allhouses"><?php the_title(); ?></h2>
<div class="addresspointer">
<i class="qode_icon_font_awesome fa fa-map-marker qode-ili-icon-holder transparent" style="color: #2c4458;"></i>
<p><?php echo $address; ?></p>
</div>
</figure></a>
<p class="link-read-more allhouses qbutton"><a href="<?php echo $link; ?>">Read More</a></p>
</div>
</div>
</div>
</div>
<?php endwhile; ?>
Share
Improve this question
edited Apr 26, 2024 at 14:17
Anna
asked Apr 26, 2024 at 13:22
AnnaAnna
213 bronze badges
0
1 Answer
Reset to default 1I have finally found a solution and for anyone interested, here is the working code :
<?php // The Query
if (is_tax() || is_category() || is_tag() ){
$qobj = $wp_query->get_queried_object();
// concatenate the query
$args = array(
'post_type' => 'houses',
'posts_per_page' => -1,
'orderby' => 'title',
'order' => 'ASC',
'tax_query' => array(
array(
'taxonomy' => $qobj->taxonomy,
'field' => 'id',
'terms' => $qobj->term_id
)
)
);
}
$area_query = new WP_Query( $args );
if ( $area_query->have_posts() );
while ($area_query->have_posts()) : $area_query->the_post();
$photo = get_the_post_thumbnail();
$titre = get_the_title();
$link = get_permalink();
$address = get_field('address');
$size = "full"; ?>
<div class="container">
<div class="row">
<div class="vc_col-sm-3">
<div class="housesinfo">
<a href="<?php echo $link; ?>"><figure class="fighouse">
<?php echo $photo; ?>
<h2 class="titlehouse allhouses"><?php the_title(); ?></h2>
<div class="addresspointer">
<i class="qode_icon_font_awesome fa fa-map-marker qode-ili-icon-holder transparent" style="color: #2c4458;"></i>
<p><?php echo $address; ?></p>
</div>
</figure></a>
<p class="link-read-more allhouses qbutton"><a href="<?php echo $link; ?>">Read More</a></p>
</div>
</div>
</div>
</div>
<?php endwhile;
wp_reset_postdata(); ?>
本文标签: wp queryShowing all posts of the current custom taxonomy on archive page
版权声明:本文标题:wp query - Showing all posts of the current custom taxonomy on archive page 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736308485a1933679.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论