0

I think I am missing something while trying to create an archive page for my post type

I decided to put three levels of data in one post type and was going to separate it by templates depending on the value of a custom field. (collection, product, variant) I am going this route because my other method of having a taxonomy>CPT1>CPT2 relationship was not building the link structure I needed.

Anyway. For my top level data, each post will be assigned the input_type=> collection.

So when going to the archive page, The archive is listing all post which I don't need. I only want it to list post marked collection.

I managed to get part of the code figured out, but it is not displaying in the grid format like I had it with the previous post type arrangement.

And for some reason, it is displaying the same title on each post, yet having different descriptions. And it is displaying post without children and not displaying some of the post with children that I want it to do. What am I missing here?

For each level of data, I am actually going need it to check to see if children are present under the given post type. Otherwise that post type will not be displayed.

Each Collection must have at at least 1 Product, each product must have at least one variant. If a collection only had one product, but that product did not have a variant defined, then that collection will not display either.

http://dev.unicriscreations.com/collection/

<?php 

get_header(); 


$args=array(

    'post_per_page'=> 12,
    'post_type' => 'uc-collections',
    'orderby' =>'ID',
    'parent' => 0,
    'post_status' => 'publish',
    'meta_query' => array(
        array( 'key'=>'input_type',
        'value'=>'collection'))
);
      $collections =  get_posts($args);

 ?>
<h1 class="page-title"><?php echo "Product Collections";  ?> </h1>

<div id="container">
    <div id="content" >
        <ul>

<?php
        foreach ( $collections as $col ) 

            {
                setup_postdata( $col ); ?> 

        <div>

                <li class="my-grid"><div >

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

                                <?php the_title(); ?>
                            </a></h2></div>
        <?php the_content(); 

                    echo '</li></div>';
        }


        ?>
        </ul>
<?php

wp_reset_postdata();
?>


    </div></div><!-- #content -->

<?php get_footer(); ?>
  • Could you use taxonomies instead - then you could make use of the Template Hierarchy and you wouldn't have to perform any custom queries. – Steven Jones Sep 5 '14 at 22:45
  • Well. I originally had my pages set u pop with a taxonomy for my collections, but that wasn't working. Though if you are talking about a taxonomy for my input types, that may work. I'll have to look at it. – Jon Cody Sep 6 '14 at 0:55

Your Answer

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

Browse other questions tagged or ask your own question.