Skip to content

Instantly share code, notes, and snippets.

@jamiemitchell
Created May 27, 2013 00:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jamiemitchell/5654636 to your computer and use it in GitHub Desktop.
Save jamiemitchell/5654636 to your computer and use it in GitHub Desktop.
I have a CPT of "product" With a custom taxonomy of "product_category". By taking advantage of the WordPress template structure, using taxonomy-product_category.php takes priority. Remove the default loop. Build a custom loop that needs to perform exactly as the original loop, but being a custom loop, i now have control of what else goes in it, …
<?php
remove_action ('genesis_loop', 'genesis_do_loop');
add_action( 'genesis_loop', 'jm_custom_do_loop' );
function jm_custom_do_loop() {
$args = array(
'post_type' => 'product',
'order_by' => 'title',
'order' => 'ASC',
'posts_per_page' => '-1',
'tax_query' => array(
array(
'taxonomy' => 'product_category',
'field' => 'slug',
'terms' => $term
)
)
);
$loop = new WP_Query( $args );
if( $loop->have_posts() ):
echo '<ul>';
while ( $loop->have_posts() ) : $loop->the_post();
echo '<li><a href="' . get_permalink() . '">' . get_the_title() . '</a></li>';
endwhile;
echo '</ul>';
endif;
wp_reset_postdata();
}
genesis();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment