获取具有相同分类术语的相关帖子

时间:2019-08-28 13:34:31

标签: php wordpress

我尝试仅显示来自textildruck帖子类型的帖子,其分类术语与我来自 <?php //get the post's venues $custom_terms = get_terms('referenzen_category'); if( $custom_terms ){ // going to hold our tax_query params $tax_query = array(); // add the relation parameter (not sure if it causes trouble if only 1 term so what the heck) if( count( $custom_terms > 1 ) ) $tax_query['relation'] = 'OR' ; // loop through venus and build a tax query foreach( $custom_terms as $custom_term ) { $tax_query[] = array( 'taxonomy' => 'referenzen_category', 'field' => 'slug', 'terms' => $custom_term->slug, ); } // put all the WP_Query args together $args = array( 'post_type' => 'referenzen', 'posts_per_page' => -1, 'tax_query' => $tax_query ); // finally run the query $loop = new WP_Query($args); if( $loop->have_posts() ) { while( $loop->have_posts() ) : $loop->the_post(); ?> <div class="card z-depth-0"> <div class="card-image"> <img src="<?php echo get_the_post_thumbnail( $referenzen->ID, 'full-width', array( ) );?> </div> <div class="card-content"> <h2><?php echo get_the_title($referenzen->ID);?></h2> <p> <?php $content_post = get_post($referenzen); $content = $content_post->post_content; $content = apply_filters('the_content', $content); $content = str_replace(']]>', ']]&gt;', $content); echo $content; ?> </p> </div> </div> <?php endwhile; wp_reset_query(); // Restore global post data stomped by the_post(). ?> } </div> </div> </div> 帖子类型的当前帖子相同。

现在我可以在前端得到这个: :count():参数必须是一个数组或一行可实现Countable的对象

有人知道我如何可以轻松地解决此问题吗?

pdfkit

0 个答案:

没有答案