Last active
June 13, 2019 02:47
-
-
Save dospuntocero/7ce02087156308e35de79befbe429ed7 to your computer and use it in GitHub Desktop.
i have a product with 2 taxonomies and i need to filter the ones that belongs to one specific taxonomy and at the same time, order the objects by category
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Template Name: Product | |
*/ | |
get_header(); | |
?> | |
<main class="wrapper"> | |
<?php $product_category_to_show_ids = get_field('product_category_to_show'); ?> | |
<?php | |
$custom_post_type = 'product-series'; | |
$category = 'product_category'; | |
$type = 'product_type'; | |
$terms = get_terms([ | |
'taxonomy' => $category, | |
'hide_empty' => true | |
]); | |
foreach ($terms as $term) : | |
$cat_posts_args = array( | |
'post_type' => $custom_post_type, | |
'posts_per_page' => -1, | |
'tax_query' => array( | |
'relation' => 'AND', | |
array( | |
'taxonomy' => $category, | |
'field' => 'id', | |
'terms' => $term->term_id, | |
'include_children' => false | |
), | |
array( | |
'taxonomy' => $type, | |
'field' => 'term_id', | |
'terms' => $product_category_to_show_ids->term_id, | |
'include_children' => false | |
) | |
) | |
); | |
$cat_posts = new WP_Query($cat_posts_args); | |
if ($cat_posts->have_posts()) : | |
?> | |
<div id="<?php echo $term->slug; ?>" class="section-head grid-x grid-padding-x"> | |
<div class="cell medium-10 medium-offset-1"> | |
<h2> | |
<?php echo $term->name; // print the category name | |
?> | |
</h2> | |
</div> | |
</div> | |
<?php | |
while ($cat_posts->have_posts()) : $cat_posts->the_post(); | |
get_template_part('partials/product'); //include the product template here | |
endwhile; | |
endif; | |
wp_reset_postdata(); | |
endforeach; | |
?> | |
</main> | |
<?php get_footer(); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment