как запросить пост в таксономии - PullRequest
0 голосов
/ 08 ноября 2019

Я создал шаблон, который отображает список постов в под-таксономии. В этом шаблоне я использую следующий код

<?php 
$term = get_term_by( 'slug', get_query_var('term'), get_query_var('taxonomy') );
$a = $term->name;
$offset = isset($_POST['offset']) ? (int)$_POST['offset'] : 0; // lấy dữ liệu phái client gởi
$getposts = new WP_query(); $getposts->query('post_type=hotcheck&tax_query=array(array(taxonomy=topics&terms='.$a.'&field=slug))&post_status=publish&showposts=5&offset='.$offset);
global $wp_query; $wp_query->in_the_loop = true; 
while ($getposts->have_posts()) : $getposts->the_post(); ?>
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; wp_reset_postdata();
die(); 
?>

Код все еще работает, но не так, как ожидалось. Каждый может увидеть абзац

$getposts->query('post_type=hotcheck&tax_query=array(array(taxonomy=topics&terms='.$a.'&field=slug))&post_status=publish&showposts=5&offset='.$offset);

Правильно или нет? Пожалуйста, помогите мне, я хочу показать все посты в SUB (ребенок) -таксономии, а не таксономии. Большое спасибо

1 Ответ

0 голосов
/ 08 ноября 2019
<?php
    $args = array(
        'post_type' => 'your_post_type', // if you want to further filter by post_type
        'tax_query' => array(
            array(
                'taxonomy' => 'type',
                'field' => 'term_id',
                'terms' => 37 // you need to know the term_id of your term "example 1"
             )
        )
    );
    $query = new WP_Query( $args ); 
?>


    while ( query->have_posts() ):
      $query->the_post();    
      ...
    endwhile
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...