Skip to content

Instantly share code, notes, and snippets.

@akella
Created February 11, 2018 08:06
Show Gist options
  • Save akella/4c380b6eba2d08e81b455674032cd671 to your computer and use it in GitHub Desktop.
Save akella/4c380b6eba2d08e81b455674032cd671 to your computer and use it in GitHub Desktop.
wp query
<?php
$args = array(
'category_name' => 'news',
'posts_per_page' => 3
);
$my_query = new WP_Query( $args );
if ( $my_query->have_posts() ) {
while ( $my_query->have_posts() ) {
$my_query->the_post();
// Post data goes here.
}
}
// Reset the `$post` data to the current post in main query.
wp_reset_postdata();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment