Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // set vars
- $post_type = 'testimonials';
- $taxonomy = 'products';
- // get all products (respective terms form "product" taxonomy)
- $products = get_terms( $taxonomy, array() );
- if ( $products ) {
- // start buildind output
- $r = '';
- foreach ( $products as $product ) {
- // get posts
- query_posts( array(
- 'tax_query' => array(
- array(
- 'taxonomy' => $taxonomy,
- 'field' => 'id',
- 'terms' => $product->term_id
- )
- ),
- 'post_type' => $post_type,
- 'posts_per_page' => 5
- )
- );
- // if there are any posts
- if ( have_posts() ) {
- // product name
- $r .= '<h2>Latest Testimonials for ' . $product->name . '</h2>';
- // the loop
- while( have_posts() ) { the_post();
- $r .= apply_filters( 'the_content', get_the_content() );
- }
- // no posts found
- } else {
- $r .= '<h2>No Testimonials for ' . $product->name . ' Product</h2>';
- }
- // reset query
- wp_reset_query();
- }
- // print out the resulting markup
- echo $r;
- }
Advertisement
Add Comment
Please, Sign In to add comment