Skip to content

Instantly share code, notes, and snippets.

@gianlucacandiotti
Last active November 2, 2019 12:56
Show Gist options
  • Save gianlucacandiotti/24f08154ec019a76b13a to your computer and use it in GitHub Desktop.
Save gianlucacandiotti/24f08154ec019a76b13a to your computer and use it in GitHub Desktop.
Get all posts for a custom post type and query them.
<?php
$type = 'custom_post_type';
$args = array(
'post_type' => $type,
'post_status' => 'publish',
'posts_per_page' => -1,
'ignore_sticky_posts'=> true
);
$my_query = null;
$my_query = new WP_Query($args);
?>
<?php if( $my_query->have_posts() ):?>
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
<?php endwhile; ?>
<?php
endif;
wp_reset_query();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment