-
-
Save onuproy/69cb0d196fe5b67cfe8ec317d1f278f4 to your computer and use it in GitHub Desktop.
Loop post type WP
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 | |
/* | |
* Loop post type: V1 | |
*/ | |
$posts = array( | |
array( 'post_type' => 'post1', 'post_per_page' => -1 ), | |
array( 'post_type' => 'post2', 'post_per_page' => -1 ), | |
array( 'post_type' => 'post3', 'post_per_page' => -1 ) | |
); | |
foreach ($posts as $post): | |
$args = array( | |
'post_type' => $post[0], | |
'post_per_page' => $post[1] | |
); | |
$my_query = new WP_Query( $args ); | |
while ( $my_query->have_posts() ) : $my_query->the_post(); | |
the_content(); | |
endwhile; | |
wp_reset_postdata(); | |
endforeach; | |
/* | |
* Loop post type: V2 | |
*/ | |
$args = array( | |
'post_type' => 'post1', | |
'post_per_page' => -1 | |
); | |
$my_query = new WP_Query( $args ); | |
while ( $my_query->have_posts() ) : $my_query->the_post(); | |
the_content(); | |
endwhile; | |
wp_reset_postdata(); | |
/* | |
* Loop post type: V3 | |
*/ | |
$my_query = new WP_Query( array( 'post_type' => 'artigo', 'paged' => get_query_var('paged') ) ); | |
while ( $my_query->have_posts() ) : $my_query->the_post(); | |
the_content(); | |
endwhile; | |
wp_pagenavi( array( 'query' => $my_query ) ); # tem que usar o plugin wp-paginavi | |
wp_reset_postdata(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment