Skip to content

Instantly share code, notes, and snippets.

@roscabgdn
Last active May 22, 2019 13:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roscabgdn/c238955dd2a01cbfc7725953eb787e01 to your computer and use it in GitHub Desktop.
Save roscabgdn/c238955dd2a01cbfc7725953eb787e01 to your computer and use it in GitHub Desktop.
Query posts by category
<?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