Created
May 27, 2013 00:58
-
-
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, …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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