Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * For WP support forum question at:
- * http://wordpress.org/support/topic/multiple-taxonomy-with-next_post_link
- */
- $produit_type = array();
- $types = get_terms( 'produit_type' );
- foreach ( $types as $type ) {
- $produit_type[] = $term->slug;
- }
- $produit_marque = array();
- $types = get_terms( 'produit_marque' );
- foreach ( $types as $type ) {
- $produit_marque[] = $term->slug;
- }
- global $post;
- $current_post[] = $post->ID;
- $args = array(
- 'post__not_in' => $current_post, // don't include current post
- 'orderby' => 'rand', // randomize list
- 'tax_query' => array(
- 'relation' => 'AND',
- array(
- 'taxonomy' => 'produit_type',
- 'field' => 'slug',
- 'terms' => $produit_type, // array of taxonomy terms of current post
- 'operator' => 'IN',
- ),
- array(
- 'taxonomy' => 'produit_marque',
- 'field' => 'slug',
- 'terms' => $produit_marque, // array of taxonomy terms of current post
- 'operator' => 'IN',
- ),
- ),
- );
- $related = new WP_Query( $args );
- echo '<ul>';
- // begin the loop
- while ( $related->have_posts() ) : $related->the_post();
- echo '<li><a href="' . get_permalink() . '">' . get_the_title() . '</a></li>';
- endwhile; // end the loop
- echo '</ul>';
- wp_reset_postdata();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement