Reputation: 11
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?
Upvotes: 1
Views: 7967
Reputation: 11
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; ?>
Upvotes: 0
Reputation: 665
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.
Upvotes: 0