hehe
hehe

Reputation: 75

why the wp_query invoke the wrong category post?

On the php file I am using the code:

<div>
    <?php
        include('../blog/wp-blog-header.php');
        define('WP_USE_THEMES', false);
        $my_query = new WP_Query(array ('cat=11', 'orderby' => 'date', 'order' => 'DESC', 'posts_per_page' => '2' ));
        while ($my_query->have_posts()) : $my_query->the_post();
    ?>
    <h3><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h3>
    <?php the_excerpt() ?>
    <?php endwhile; ?>
    <?php wp_reset_postdata();?>
</div>
<ul>
    <?php
        $my_query = new WP_Query(array ('cat=11', 'orderby' => 'date', 'order' => 'DESC', 'posts_per_page' => '10','offset' => 2  ) );
        $i=0;
        while ($my_query->have_posts()) : $my_query->the_post();
    ?>
    <li  <?php if($i==4) echo 'class="except"'; ?>>
        <a href="<?php the_permalink() ?>" ><?php the_title(); ?></a>
    </li>
    <?php $i++;?>
    <?php endwhile; ?>
    <?php wp_reset_postdata();?>
</ul>

The above code not only invoked the category whose id is 11, it also invoked other category . Why?

Upvotes: 0

Views: 371

Answers (1)

Raptor
Raptor

Reputation: 54212

Replace

$my_query = new WP_Query(array ('cat=11', 'orderby' => 'date', 'order' => 'DESC', 'posts_per_page' => '10','offset' => 2  ) );

with:

$my_query = new WP_Query(array ('cat' => 11, 'orderby' => 'date', 'order' => 'DESC', 'posts_per_page' => '10','offset' => 2  ) );

Reference: http://codex.wordpress.org/Class_Reference/WP_Query

Upvotes: 1

Related Questions