Answer the question
In order to leave comments, you need to log in
How to make a universal function for displaying records?
There is a function that displays all records of a given type:
$args = array(
'post_type' => 'works',
'numberposts' => -1
);
$lastposts = get_posts( $args );
foreach( $lastposts as $post ){ setup_postdata($post);
get_template_part( 'works-item' );
}
wp_reset_postdata();
Answer the question
In order to leave comments, you need to log in
Something like this (I wrote from memory, so errors are possible):
$term = get_queried_object();
$term_slug = $term->slug;
$_posts = new WP_Query( array(
'post_type' => 'works',
'posts_per_page' => 10,
'tax_query' => array(
array(
'taxonomy' => 'category', // или вашу таксономию
'field' => 'slug',
'terms' => $term_slug,
),
),
) );
if ( $_posts->have_posts() ) :
while ( $_posts->have_posts() ) :
$_posts->the_post();
get_template_part( 'works-item' );
endwhile;
endif;
wp_reset_postdata();
By default, 'category' => 0 is passed to the function, so add the optional parameter $category = 0 to your function, and set the value to your array of arguments:
$args['category'] = $category;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question