Last active
August 29, 2015 14:10
-
-
Save niksudan/ae4fb59583499b9b2714 to your computer and use it in GitHub Desktop.
Get posts loops [WordPress]
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 | |
/** | |
* Using get_posts() function | |
*/ | |
$custom_posts = get_posts( array( | |
'post_type' => 'post_type_name', | |
) ); | |
$tmp_post = $post; foreach ( $custom_posts as $post ) : setup_postdata( $post ); | |
// loop | |
endforeach; $post = $tmp_post; | |
/** | |
* Using WP_Query object | |
*/ | |
$query = new WP_Query( array( | |
'post_type' => 'post_type_name', | |
) ); | |
if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); | |
// loop | |
endwhile; endif; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment