Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make a Wordpress archive page for custom posts and taxonomies?

I'm a trying to set up an archive page with custom post types and custom taxonomy in Wordpress.

I have created the custom post type: “package” and the custom taxonomy: “software”. My problem is that when I try to look at localhost:8888/software/aperture I get all the posts of the type package instead of just the ones with the custom taxonomy aperture selected. I am using the following code:

<?php
        $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
        ?>
        <h1><?php echo $term->name;?> Presets</h1>
        <div class="intro2">
            <p>
            <?php echo $term->description;?>
            </p>
        </div>
        <?php query_posts('post_type=package'); ?>
         <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
            <!-- Product Start -->
            <div class="product">
                <div class="product_top"></div>
                <div class="product_content">
                        <div class="product_image">
                        <a href="<?php the_permalink()?>">
                            <?php echo get_the_post_thumbnail( $id, $size, $attr ); ?> 
                        </div>
                        <a href="<?php the_permalink()?>" class="title"><?php the_title()?></a>
                            <?php the_excerpt()?>                   
                        <div class="theprice">
                            <?php
                            $price = get_post_meta($post->ID, "price", true);
                            echo "$".$price;
                            ?>
                        </div>
                        <a href="<?php the_permalink()?>" class="button calltoaction"><span>See The Presets</span></a>
                        <div class="clearboth"></div>
                </div>
            </div>
         <?php endwhile; else: ?>
         <p>Sorry, no posts matched your criteria.</p>
         <?php endif; ?>    

How do I get this archive page to just show posts of the type package form the current selected item in the custom taxonomy?

By the way I used the plugins "More Types" and "More Taxonomies" to set it up.

Update: solved it:

Solved it myself by adding by setting Allow queries to true in the more taxonomies plugin and setting the variable to presets. Then I changed the query to:<?php query_posts(array( 'post_type'=>'package', 'presets' => $term->slug, 'posts_per_page' => -1 )); ?>

like image 688
Thomas Avatar asked Nov 14 '22 22:11

Thomas


1 Answers

Modify <?php query_posts('post_type=package'); ?>

with

<?php query_posts(array('post_type'=> 'package',array('taxonomy' => 'software'))); ?>

or

<?php query_posts(array('post_type'=> 'package','taxonomy' => 'software')); ?>
like image 164
zuzuleinen Avatar answered Dec 19 '22 17:12

zuzuleinen