Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've been trying to display posts that I've categorized as "news-categories". My goal is to only display 4 posts on sidebar of "cbs-news" slug underneath "news-categories" category. By below mention code all the post underneath "cbs-news" are displaying. But i need to display only 4 latest post.

 <ul class="list4 martop5">
    <?php 
            $args = array('tax_query' => array( array('taxonomy' => 'news-categories', 'posts_per_page' => '5', 'field' => 'slug','terms' => 'cbs-news',
            'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1 )
            )));
            $the_query = new WP_Query( $args );
            if($the_query->have_posts() ) : 
            //have_posts("showposts=4");
            while ( $the_query->have_posts() ) : $the_query->the_post();
            ?>
        <li>
           <a href="<?php echo get_permalink(); ?>"><?php the_title(); ?></a>
        </li><!-- /.service -->

    <?php endwhile; else: ?>

        <p>Nothing Here.</p>

    <?php endif; wp_reset_postdata(); ?>
share|improve this question

2 Answers 2

up vote 1 down vote accepted

You write the wrong code

$paged = get_query_var('paged') ? get_query_var('paged') : 1;
$args = array('posts_per_page' => '5', 
              'paged' => $paged,
              'tax_query' => array( array('taxonomy' => 'news-categories',
                                          'field' => 'slug',
                                          'terms' => 'cbs-news')
                                  )
              );

You can also take help in WP_Query

share|improve this answer
    
Wow, Its working...Thanks for the help..:) Waise kithe de ho bhaji..:) –  Gaurav Jul 23 '13 at 9:43
    
New Delhi de :D –  ksr89 Jul 25 '13 at 4:19

Your query is not correct, try this instead :

 $paged = ( get_query_var('paged') ? get_query_var('paged') : 1 );

 $args = array(
 'tax_query' => array( 
                  array('taxonomy' => 'news-categories',
                        'field' => 'slug',
                        'terms' => 'cbs-news'
                      )
               ), 
 'posts_per_page' => '5',
 'paged' => $paged
 );
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.