Answer the question
In order to leave comments, you need to log in
Outputting posts of a specific taxonomy?
The question is trite, I'm ashamed, but working on the project for which the question arose, with almost no knowledge of php, I hesitated. I need to display a taxonomy, the taxonomy is called 'region'. The custom post type for this taxonomy is called 'women'. The template code for taxonomy output (taxonomy-region.php) is currently unfinished (there is no check for taxonomy, it just displays everything from 'women') and looks like this (cut out the extra, all sorts of divs, etc.):
<?php
/**
* Template Name: Region
*
*/
$post_type = 'women';
get_header(); ?>
<div id="content-wrap" class="container clr">
<?php while ( have_posts() ) : the_post(); ?>
<?php endwhile; ?>
<div class="row">
<?php
global $post, $paged, $more;
$more = 0;
if ( get_query_var( 'paged' ) ) {
$paged = get_query_var( 'paged' );
} else if ( get_query_var( 'page' ) ) {
$paged = get_query_var( 'page' );
} else {
$paged = 1;
}
// Query posts
$wp_query = new WP_Query( array(
'post_type' => 'women',
'paged' => $paged,
'category__not_in' => wpex_blog_exclude_categories( true ),
'orderby' => 'rand',
) );
if ( $wp_query->posts ) : ?>
<div id="blog-entries" class="clr <?php wpex_blog_wrap_classes(); ?>">
<?php $wpex_count = 0; ?>
<?php while ( have_posts() ) : the_post(); ?>
<div class="wpb_column vc_column_container vc_col-sm-3">
.....
.....
.....
</div>
<?php endwhile; ?>
</div></div><!-- #blog-entries -->
<?php wp_reset_postdata(); wp_reset_query(); ?>
<?php wpex_hook_content_bottom(); ?>
</div><!-- #content -->
<?php wpex_hook_content_after(); ?>
<?php get_footer(); ?>
?>
Answer the question
In order to leave comments, you need to log in
I confess that I'm too lazy to understand your code. I just copied and pasted the code from my project, where there was a similar task:
$term = get_queried_object();
$term_slug = $term->slug;
$_posts = new WP_Query( array(
'post_type' => 'women',
'posts_per_page' => 10,
'tax_query' => array(
array(
'taxonomy' => 'region',
'field' => 'slug',
'terms' => $term_slug,
),
),
) );
if ( $_posts->have_posts() ) :
while ( $_posts->have_posts() ) :
$_posts->the_post();
get_template_part( 'template-parts/content', 'women' );
endwhile;
the_posts_navigation();
else :
get_template_part( 'template-parts/content', 'none' );
endif;
wp_reset_postdata();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question