Get all posts from custom taxonomy in Wordpress

后端 未结 4 594
广开言路
广开言路 2020-12-25 09:51

Is there a way to get all the posts from a taxonomy in Wordpress ?

In taxonomy.php, I have this code that gets the posts from the term related to the cu

4条回答
  •  星月不相逢
    2020-12-25 10:07

    While in the query loop for terms, you can collect all post references in an array and use that later in a new WP_Query.

    $post__in = array(); 
    while ( $terms_query->have_posts() ) : $terms_query->the_post();
        // Collect posts by reference for each term
        $post__in[] = get_the_ID();
    endwhile;
    
    ...
    
    $args = array();
    $args['post__in'] = $post__in;
    $args['orderby'] = 'post__in';
    $other_query = new WP_Query( $args );
    

提交回复
热议问题