wordpress Получить все посты (записи) для данного элемента таксономии (term)
Primary tabs
По сути как и обычный запрос, но нужно использовать дополнительный элемент tax_query, который также принимает вложенный массив параметров:
$args = array(
'post_type' => 'recipe_cpt',
'tax_query' => array(
array(
'taxonomy' => 'recipe_tx',
'field' => 'term_id',
'terms' => 37
)
)
);
$query = new WP_Query( $args ); Например:
$post_type = 'products'; // тип записи для которого выводить
global $wp_query;
$original_query = $wp_query;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$custom_post_type = new WP_Query(array(
'post_type' => $post_type,
'orderby' => 'date',
'order' => 'DESC',
'posts_per_page' => 100,
'paged' => $paged,
'tax_query' => array(
array(
'taxonomy' => $term->taxonomy,
'field' => 'term_id',
'terms' => $term->term_id
)
)
));
Получить только посты-потомки первого уровня
Чтобы получить только непосредственных потомком данной записи используйте
'include_children' => false
например:
$posts_array = get_posts( array( 'posts_per_page' => -1, 'post_type' => 'uslugi', 'tax_query' => array( array( 'taxonomy' => 'uslugicat', 'field' => 'term_id', 'terms' => $term_id, 'include_children' => false ) ) ) );
- Log in to post comments
- 2872 reads