• Hi,

    I am trying to change the following code to list 10 posts:

    $the_query = new WP_Query('showposts='. $posts .'&orderby=post_date&order=desc');
    	while ($the_query->have_posts()) : $the_query->the_post();

    I have tried the following without success:

    $the_query = new WP_Query('showposts='. $posts .'&orderby=post_date&order=desc', 'posts_per_page = 10');
    	while ($the_query->have_posts()) : $the_query->the_post();
    $the_query = new WP_Query('showposts='. $posts .'&orderby=post_date&order=desc', 'posts_per_page' => 10);
    	while ($the_query->have_posts()) : $the_query->the_post();
    $the_query = new WP_Query('showposts='. $posts .'&orderby=post_date&order=desc', 'posts_per_page=10');
    	while ($the_query->have_posts()) : $the_query->the_post();

    The first one does nothing, the second and third list PHP errors on loading the site.

    This code does list 10, but not in the way that I need:

    $loop = new WP_Query( array( 'post_type' => 'post', 'posts_per_page' => 10 ) );
    while ( $loop->have_posts() ) : $loop->the_post();

    Should I use the original query as an array?

Viewing 1 replies (of 1 total)
  • $the_query = new WP_Query('orderby=post_date&order=desc&posts_per_page=10');
    	while ($the_query->have_posts()) : $the_query->the_post();

    showposts is now deprecated in flavor of posts_per_page

Viewing 1 replies (of 1 total)
  • The topic ‘Edit $query statement to list 10 results’ is closed to new replies.