Created
August 16, 2016 06:33
-
-
Save mzo84/5cc9754501a1db253d49c314adf6be5c to your computer and use it in GitHub Desktop.
Customizing the Loop with WP_Query
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php // The WordPress Loop - customized with WP_Query | |
$custom_query = new WP_Query('cat=-9'); // exclude Asides category | |
while($custom_query->have_posts()) : $custom_query->the_post(); | |
... | |
endwhile; | |
wp_reset_postdata(); // reset the query | |
?> | |
// more examples | |
<?php | |
$custom_query = new WP_Query('cat=-7,-8,-9'); // exclude any categories | |
$custom_query = new WP_Query('posts_per_page=3'); // limit number of posts | |
$custom_query = new WP_Query('order=ASC'); // reverse the post order | |
$custom_query = new WP_Query('cat=-7,-8,-9&posts_per_page=3&order=ASC'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment