Why is WP_Query not working with category_name?

Why on earth is this piece of code not working?

    $my_query = new WP_Query('category_name=feature');
    while ($my_query->have_posts()) : $my_query->the_post();
        echo 'test';
    endwhile;

I’ve tried with Feature and feature, no difference.
I need to get post by category name.

Any help appreciated.

update

This is not working either: $my_query = new WP_Query('cat=3');

code

// index.php

<?php
    include_once('header.php');
?>

<div id="fp-slider-container" class="blue-gradient">
    <div class="main-content-container">
        <?php
        query_posts( 'cat=3&posts_per_page=5' );

        while ( have_posts() ) : the_post();
            echo 'test';
        endwhile;


        ?>
    </div>
</div>

<?php
    include_once('footer.php');
?>

3 s
3

A common pitfall is the fact that:

category_name takes the category SLUG NOT the name as attribute

This is often mistaken.

Leave a Comment