Last active
May 22, 2019 13:13
-
-
Save roscabgdn/c238955dd2a01cbfc7725953eb787e01 to your computer and use it in GitHub Desktop.
Query posts by category
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 | |
// Query arguments : https://codex.wordpress.org/Class_Reference/WP_Query | |
$args = array( | |
'posts_per_page'=> 5, | |
'orderby' => 'date', | |
'order' => 'DESC', | |
'category' => 'slider' | |
); | |
// create the query | |
$slider = new WP_Query($args); | |
// loop through the new created query | |
if ( $slider->have_posts() ) : | |
while ( $slider->have_posts() ) : $slider->the_post(); | |
// loop content | |
endwhile; | |
else: | |
echo __( 'There are no posts to show', 'textdomain' ); | |
endif; | |
wp_reset_postdata(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment