Last active
August 29, 2015 14:05
-
-
Save michaelschofield/f706f809eaa733d2e83e to your computer and use it in GitHub Desktop.
Loop any Post-Type in Specific Category
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 | |
// Fetch all posts, regardless of post-type, in "my_category". | |
$args = array( | |
'post_type' => 'any', | |
'category_name' => 'my_category' | |
); | |
// Call the $args ^ in a new WP_Query(). | |
$the_query = new WP_Query( $args ); | |
// The default loop is `if ( have_posts() ) : while ( have_posts() ) : the_post();` | |
// but after changing the query, we have to add $the_query-> before each hook. | |
if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); | |
/* Close the PHP tag */ ?> | |
<!-- The <article> post HTML here. Pretend. --> | |
<?php // More PHP | |
endwhile; // This closes the `while( $the_query->have_posts() )` condition. | |
endif; // This closes the `if( $the_query-> have_posts() )` condition. | |
// When you modify the loop, you have to "reset" it - otherwise your modifications might | |
// mess up what WP does out of the box. | |
wp_reset_postdata(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment