Skip to content

Instantly share code, notes, and snippets.

@eliasfaical
Last active March 6, 2021 20:52
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 eliasfaical/5636598 to your computer and use it in GitHub Desktop.
Save eliasfaical/5636598 to your computer and use it in GitHub Desktop.
Loop post type WP
<?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