View wordpress posts by category

0

I use the code below to display posts in the ID 1 category , but instead of using the ID category, I'd like to use slug EX: cat = news

<?php query_posts('cat=1'); while ( have_posts() ) : the_post(); ?>
    
asked by anonymous 26.01.2017 / 23:12

1 answer

1

According to Wordpress documentation , I believe this will solve your problem:

query_posts( array(
    'category_name'  => 'my-category-slug',
    'posts_per_page' => -1
) );
    
27.01.2017 / 01:01