Skip to content

Instantly share code, notes, and snippets.

@ajithrn
Last active August 29, 2015 13:56
Show Gist options
  • Save ajithrn/9157446 to your computer and use it in GitHub Desktop.
Save ajithrn/9157446 to your computer and use it in GitHub Desktop.
Wordpress: wp query
<?php
/** Wordpress general query
* http://codex.wordpress.org/Class_Reference/WP_Query
* */
// WP_Query arguments
$custom_args = array ( 'post_type' => 'custom_post', 'post_status' => 'publish', 'paged' => $paged, 'posts_per_page' => '5', 'order' => 'DESC', 'orderby' => 'date', );
// The Query
$custom_query = new WP_Query( $custom_args );
// The Loop
if ( $custom_query->have_posts() ):
while ( $custom_query->have_posts() ):
$custom_query->the_post();
// do something
endwhile;
else:
// no posts found
endif;
// Restore original Post Data
wp_reset_postdata();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment