Skip to content

Instantly share code, notes, and snippets.

@beardlessman
Forked from akella/wp_query.php
Created March 13, 2018 09:41
Show Gist options
  • Save beardlessman/2f9cf530b0972dadb60ab248aa1060f9 to your computer and use it in GitHub Desktop.
Save beardlessman/2f9cf530b0972dadb60ab248aa1060f9 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