Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

jillianmariegraphics on "Taxonomy Archive - Sort and Filter by Terms"

$
0
0

I've been struggling over this concept for days and am hoping to get some help as I am a beginner at using custom post types.

I'm setting up a site to display an inventory of showroom products.

Custom Post Type: Products

Taxonomies related and their terms:
Model Year (2014, 2013, 2012)
Manufacturer (Company 1, Company 2)
Condition (New, Used)

In the "New Products" archive, I want to display all products in "New" condition, ordered by their model year with 2014 displaying first.

I did try adding a custom field (year_model) to be able to orderby the meta_value, although this didn't work.

Here is the code I have so far to display all new models.

<?php get_header();
$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
?>

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

<section id="post-<?php the_ID(); ?>">
<article>
<div class="entry-content clearfix">
		<h2 class="entry-title"><?php echo apply_filters( 'the_title', $term->name ); ?> Products</h2>
<?php
$locations_query = new WP_Query( array(
	  'post_type' => 'products',
	  'posts_per_page' => 15,
	  //'meta_key'      => 'year_model', // the meta key of custom field
          //'orderby'      => 'meta_value',
          //'order'         => 'ASC',
'tax_query' => array(
		  array(
 			 'taxonomy' => 'condition',
			 'field' => 'slug',
			 'terms' => 'new'
		)
	)
) );
// Display the custom loop
if ( $locations_query->have_posts() ): ?>
<ul class="posts">
<?php while ( $locations_query->have_posts() ) : $locations_query->the_post(); ?>
<li>
	<a href="<?php the_permalink(); ?>" rel="bookmark"><h2 class="entry-title"> <?php the_title(); ?></h2>
	<div class="post-featured-image"><?php the_post_thumbnail(); ?></div></a>
	</li>
	<?php endwhile; wp_reset_postdata(); ?>
</ul><!--// end entry-header -->
<?php endif; ?>
</div><!--entry-content-->
</article>
</section>
</div><!--content-->
</div><!--container-->

Viewing all articles
Browse latest Browse all 8245

Trending Articles