1
votes

I created a custom post type called, "Portfolio," using a plugin called Custom Post Type UI v0.7.1. I have created several categories for it, such as Logos, Packaging, etc.

I need to use archive.php to filter by category.

Right now I have an archive-portfolio.php that includes this code:

<?php $wp_query = null; $wp_query = $temp;?>
<?php $temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query(); ?>
<?php $wp_query->query("post_type=portfolio&". $catinclude ."&paged=".$paged.'&showposts=20'); ?>

<ul>
    <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
        echo '<li><a href="'; the_permalink(); echo '">';
        echo '<strong>'; the_title();
        echo '</strong>';
        echo '</a></li>';
    ?>
    <?php endwhile; ?>
</ul>

I've tried using URLs like /?category_name=logos and /?cat=logos but none of that has worked; it just displays all portfolio items regardless of category.

The Portfolio custom post type has "Archive" and "Hierarchical" enabled.

For built-in taxonomies, it has categories and tags enabled as well.

Any ideas?

2
not really an answer, but the first 5 lines should be grouped together. no sense in closing and opening php tags like that. edit: And the endwhile should be grouped with the above line too.Steve

2 Answers

0
votes

I would use query_posts like this below, you can probably also simplify the code:

<?php query_posts( array( 'post_type' => 'portfolio', 'showposts' => 10, 'orderby' => 'date', 'order' => 'desc')); ?>

<ul>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <li>
         <a href="<?php the_permalink();?>">
             <strong><?php the_title(); ?></strong>
         </a>
    </li>
<?php endwhile; ?>
</ul>
<?php endif; ?>

You can find the parameters that query_posts accepts in the WordPress Codex.

0
votes

I actually ended up getting it to work with this:

            <?php 
            $wp_query = null; $wp_query = $temp;
            $temp = $wp_query;
            $wp_query= null;
            $wp_query = new WP_Query();
            $wp_query->query("post_type=portfolio&category_name=" . $_GET["category"] . "&". $catinclude ."&paged=".$paged.'&showposts=20'); 
            if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
            ...
            <?php endwhile; ?>