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
Add a comment  | 

1 Answer 1

Reset to default 1

I 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