$args = array( 'post_type' => 'post', 'posts_per_page' => 5 ); $query = new WP_Query( $args ); if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); // display the post content endwhile; endif;
$args = array( 'tag' => 'tech', // tag slug 'posts_per_page' => 10 ); $query = new WP_Query( $args ); if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); // display the post content endwhile; endif;
$args = array( 'category_name' => 'news', // category slug 'posts_per_page' => 10 ); $query = new WP_Query( $args ); if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); // display the post content endwhile; endif;WP_Query is a part of the WordPress core, which means it's a package that's included with WordPress.