0

Is it possible to have a page which shows a list of the custom tax parents only and only 1 post per custom tax, i/e link to the parent archive

So even though the custom tax may have x number of posts and x number of child custom tax's its basically just showing a link to that custom tax archive page parent.

SO essentially an archive page just for the custom tax parents ignoring the posts within.

I can do this manually with a page template and query each custom tax individually but wondered if it could be done dynamically.

I have the following but its spitting out all the posts within the category. Perhaps get_terms is needed i'm not sure?

<?php

                    $args = array(
                       'posts_per_page' => -1,
                        'post_type' => 'product',
                        'tax_query' => array(
                                    array(
                                        'taxonomy' => 'product-area',
                                        'field' => 'slug',
                                        'terms' => array('insulation','drylining-plastering'),
                                        'include_children' => false
                                    )
                                )
                    );
                    $products_tax = new WP_Query( $args );


                   if($products_tax->have_posts()) : 
                      while($products_tax->have_posts()) : 
                         $products_tax->the_post();
                ?>

                <h2><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
                    <?php the_title(); ?>
                </a></h2>


                <?php
                      endwhile;
                   else: 
                ?>

                      Oops, there are no posts.

                <?php
                   endif; 
                   wp_reset_postdata();
                ?>
0

I've managed to figure this out myself, so if anyone out there needs some help please try the following...

Using the get_terms rather than trying to query it directly.

<?php 

                    $terms = get_terms('custom-tax-name', array('hierarchical' => false));
                    foreach ($terms as $term) {


                    $term_link = get_term_link( $term );

                     if ( have_posts() ) :

                 ?>


                     <a href="<?php echo $term_link; ?>">
                     <?php echo '<h3>'.$term->name.'</h3>'; ?>


                    </a>

                <?php endif; wp_reset_query(); } ?>
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.